Package Manager Command
A package manager is a tool for automating the process of installation, upgrading, configuring, or removal of programs in a consistent manner. In the CUI environment, you can use package managers by running commands. The commands can be different depending on the Linux OS distribution.
Debian-based and RPM-based
There are two major package manager groups – Debian-based and RPM-based. Debian and Ubuntu use apt
, apt-get
, or dpkg
, or snap
commands while RHEL and CentOS use rpm
, yum
, or dnf
commands.
Installing a new command or library
One of the most basic situations when package managers can be used is installing a new command or library that has not been installed on your computer yet. For example, the tree
command (which will be explained in the next section) may not be preinstalled on your OS. To use the command, you need to install it using a package manager. When you run the tree
command on Ubuntu OS, you may see a message like the one below.
tree
Command 'tree' not found, but can be installed with:
sudo snap install tree # version 1.8.0+pkg-3fd6, or
sudo apt install tree # version 1.8.0-1
See 'snap info tree' for additional versions.
apt install (for Ubuntu)
Tips: apt update
To maintain proper dependencies and install the right version of a program, it is highly recommended to run the "apt update
" command first before running the installation of a new command or library.
sudo apt update
sudo apt install [library]
To install the tree
command, run sudo apt install tree
after the sudo apt update
command.
sudo apt update
sudo apt install tree
Once you successfully install it, you can run the command.
Reading package lists... Done
Building dependency tree
:
Setting up tree (1.8.0-1) ...
Processing triggers for man-db (2.9.1-1) ...
yum install (for CentOS)
As explained, the package manager command differs by Linux distribution. For example, you can use the yum
command for CentOS as shown below.
sudo yum install tree
Uninstall a command or library
When you want to uninstall the command or library, you can also use the package manager command. For the tree
command case, use the command below.
sudo apt remove tree
You will be asked whether you want to continue. Once you answer y, the command will be deleted from the computer.
Reading package lists... Done
Building dependency tree
:
Do you want to continue? [Y/n] y
:
(Reading database ... 59631 files and directories currently installed.)
Removing tree (1.8.0-1) ...
Processing triggers for man-db (2.9.1-1) ...