2024-02-17
The most common use of APT is installing software. This is done using the apt install command followed by the package name. For example, to install the vim text editor:
sudo apt install vimThe sudo command is essential here, as installing software requires root privileges. You’ll be prompted for your password. You can install multiple packages at once:
sudo apt install vim curl gitAPT will automatically download and install the packages, along with any dependencies they require.
Before installing any new software, it’s good practice to update your local package lists. These lists contain information about available packages and their versions from the repositories your system is configured to use. This is done with:
sudo apt updateThis command downloads the latest package information from the repositories, ensuring you’re installing the most recent versions.
Once your package lists are updated, you can upgrade all installed packages to their latest versions using:
sudo apt upgradeThis command will identify any packages with newer versions available and prompt you for confirmation before upgrading. Be aware that this might take some time depending on your internet connection and the number of packages to be upgraded. For a full system upgrade including removing obsolete packages, use:
sudo apt full-upgradeTo remove a package, use the apt remove command:
sudo apt remove vimThis removes the specified package but leaves any configuration files intact. If you wish to completely remove the package and its configuration files, use:
sudo apt purge vimAPT provides a convenient way to search for packages using the apt search command:
apt search firefoxThis command searches for packages containing “firefox” in their name or description. You can refine your search using keywords and wildcards.
After installing and uninstalling packages, you might have unused dependencies left on your system. apt autoremove cleans these up:
sudo apt autoremoveOld downloaded package files can consume considerable disk space. Use apt autoclean to remove them:
sudo apt autocleanTo see a list of all installed packages, use:
dpkg --get-selections | grep installThis uses dpkg, another package management utility often used in conjunction with APT.
APT allows you to manage different software repositories. Adding a new repository usually involves adding a line to your /etc/apt/sources.list file. However, this should be done cautiously and only after verifying the repository’s legitimacy to avoid security risks. For example, to add a repository for a specific application, you might add a line similar to this (replace with the actual URL):
deb http://example.com/repo/ubuntu focal main
After adding a new repository, you must run sudo apt update to refresh the package list. Then you can install packages from that repository. This is an advanced technique, and exercising caution is strongly advised.