linux package manager

steps to download and run programs in Linux = Using Package Manager:

Once linux is installed and running, you will want to download and install new software on your system. One way to install any new software on your computer is to download source code from internet, then compile it on local machine using Makefile provided, then install it in appropriate dir. This process is very cumbersome, and is suitable for advanced users only. However for layman users, this process can all be automated by using package managers that come preinstalled on linux OS. However for these pacakage managers to be able to download, compile and install the software, the software needs to be in a package in a special format. The creator of the software should provide their software in specific format for that package manager, or else the package manager can't be used. Fortunately, most of the software that you will ever encounter is available in multiple package formats, so they can be used with almost all package managers.

Package Manager:

A package manager or package management system is a collection of software tools that automates the process of installing, upgrading, configuring, and removing computer programs for an OS on a system. A package manager deals with packages which are distributions of software and data in archive files. Packages contain metadata, such as the software's name, description of its purpose, version number, vendor, checksum, and a list of computer_programming dependencies necessary for the software to run properly. Package managers are designed to eliminate the need for manual installs and updates. Running any package manager requires admin rights, so you have to precede cmds with "sudo" (see in "linux cmds" section for more details on sudo).

Following are the package managers and package formats supported by various linux distro. As you can see there are only 2 formats that will suffice all linux users - .deb and .rpm formats.

1. Deb (Debian) format: All Debian and its derivatives such as Ubuntu, Linux Mint, support .deb package format. The package manager is apt (advanced package tool). APT resolves dependency problems and retrieves requested packages from designated package repositories. APT delegates the actual installation and removal of packages to dpkg. So, instead of directly typing dpkg cmds, APT handles it for us. We type apt commands on command line to interact with APT. NOTE: APT is different than apt cmd line tools. There are various apt cmd line tools to interact with APT pkg mgr. Some examples of cmd line tools are apt-get, apt-cache, aptitude, apt, etc. Until 2016, we had apt-get and apt-cache as 2 most popular cmd line tools for APT. However, cmd line tool "apt" was introduced in Ubuntu 16.04, to combine cmds from both of these into one, and make cmds simpler. apt is now recommended cmd to use with APT. You will still see lots of documentation for apt-get and apt-cache online, and you can continue to use them (as they will still work), but apt is the path forward. So, I'll just show "apt" cmds from now on.

Few of the important apt cmds here: https://itsfoss.com/apt-command-guide/

  • sudo apt update => updates the pkg database repository, so that APT knows if there are any newer packages available, for software already installed on your system. You will see pkg info being retrieved from various servers. You need to run this cmd, before installing any new pkg, so that you get the latest in the repo.
  • sudo apt upgrade => once the pkg database is updated using above cmd, we can upgrade all installed pkg with this cmd. If update cmd not run before upgrade, then APT repository may not that there are latest updates available, and will say, it's up to date.
  • apt search php => this is neat way to find out or search for any packages which contains the specified term, here it searches for any pkg containing term "php" in it. It will generally show hundreds of pkg with that name, so it's usually hard to determine which pkg to choose. i.e if we see 100's of pkg with name "php", we don't know which one to download. Some of these are basic pkg, while some are additional modules for that pkg, etc. Usually search on internet will show what all to download. NOTE: no sudo reqd, as it doesn't make any changes to your system.
  • apt show php => will show additional info about pkg "php". Useful to know, before you install that pkg.
  • sudo apt install <pkg_name> => most used cmd. installs required pkg, like apache2, tcl, etc
  • sudo apt remove <pkg_name> =>removes the pkg.

These are some important directories associated with APT:

/etc/apt has the apt configuration folders and files. All files/folders in /etc/apt are:

  • sources.list: Locations to fetch packages from. This has path to locate the desired packages, which might be available on the network or a removable storage medium, for example, and retrieve them, and also obtain information about available (but not installed) packages.  On my system, this file has 1 line as follows:
    • #deb cdrom:[Linux Mint 19 _Tara_ - Release amd64 20180717]/ bionic contrib main non-free => This line is commented out. So, apt automatically searches other files in sources.list.d for location of packages:
  • sources.list.d/official-package-repositories.list => This has the location of where to fetch packages from:
    • deb http://packages.linuxmint.com tara main upstream import backport => We see many more links from ubuntu, canonical, etc.
  • To use official debian repository which contains about 50K packages, we could insert a line like this in any of above file, and then run "apt update"
    • deb http://ftp.debian.org/debian stable main contrib non-free => Now, APT will use this link to download stable pkg
  •  apt.conf.d => APT configuration file fragments.
  • preferences: version preferences file. This is where you would specify a preference to get certain packages from a separate source or from a different version of a distribution

/var/cache/apt/archives/: storage area for retrieved package files. It has all .deb files that are downloaded. deb files are readable text files. This is a good place to see what was downloaded for let's say "sql" package.

/var/lib/apt/lists/: storage area for state information for each package resource specified in sources.list

Ex: to install a new scripting language called tcl (which is not installed by default on Linux Mint), we run these cmds from any dir in a terminal:

sudo apt install tcl => sudo needed to run as super user since root permissions are needed to run apt. It asks for user's password, and then shows what's going to get installed, and asks if you want to continue. On pressing Y, it downloads pkg. shows lines like this ...

Get:1 http://archive.ubuntu.com/ubuntu bionic/main amd64 libtcl8.6 amd64 8.6.8+dfsg-3 [881 kB] => download link for tcl pkg

Preparing to unpack .../libtcl8.6_8.6.8+dfsg-3_amd64.deb ... => .deb file for tcl downloaded from link above,
Unpacking libtcl8.6:amd64 (8.6.8+dfsg-3) ... =>

Setting up tcl8.6 (8.6.8+dfsg-3) ... => This finally installs tcl on your m/c.

NOTE: Instead of using command line above, Linux Mint provides graphical software called "synaptics package manager" and "software manager". We can use this too to install new software just by searching for that and clicking "install". However if any of these is open, and you try to run apt cmd on cmd line in terminal, you may get a lock error. So, close these before using cmd line i/f on terminal.

 

2. RPM (Red Hat package manager) format: All Fedora and it's derivatives as CentOS, RHEL, and SUSE, OpenSUSE support .rpm package format. RPM is delivered as a single file either as .src.rpm (for source pkg) or as .<arch>.rpm(for binary pkg). Package manager is yum.

Yum (yellowdog Updater Modified). Few of the imp cmds:

  • sudo yum update => updates the pkg database repository, so that yum knows if there are any newer packages available, for software already installed on your system. -y option updates w/o asking for your confirmation. Similar to apt, you need to run this cmd, before installing any new pkg, so that you get the latest in the repo.
  • sudo yum upgrade => once the pkg database is updated, we can upgrade all installed pkg with this cmd. 
  • sudo yum upgrade httpd -y =>this upgrades specific pkg named "httpd". -y upgrades w/o asking for confirmation
  • yum search httpd => searches for any pkg containing term "httpd" in it
  • yum info httpd => shows additional info about pkg "httpd".
  • sudo yum install <pkg_name> => most used cmd. installs required pkg, like apache2, tcl, etc
  • sudo yum remove <pkg_name> =>removes the pkg. This will figure out all files associated with that pkg, and cleanly remove them. Linux "rm" cmd should NOT be used to remove packages.

 ex: upgrading firefox:

  1. sudo yum update => updates local repo.
  2. sudo yum info firefox => This gives info on installed firefox pkg, as well as the latest one available. For me, it was showing intalled firefox version as 80.xx, while available was showing as 93.0.0. That meant my pkg was out of date. However, for latest avilable pkg to show, we should have run above "update" cmd, else yum will show latest based on when the repo was last updated.
  3. sudo yum upgrade firefox => This finally upgrades firefox to latest 93.0.0

On top of individual pkg, there are also groups, of which there are 2 kinds:

1. environment groups: consists of a group of packages define how the server needs to be built, it can be Web Server, Minimal installation or server with the graphical interface.

2. groups: consists of all other groups of software like “Development Tools” or “System Administration Tools”. We can apply yum to these groups too

  • yum groups => prints summary of groups. On my centOS laptop, it shows 12 Environment groups and 25 groups.
  • yum grouplist => prints all avilable groups with group names. Env groups are Cinnamon Desktop, Mate Desktop, Basic Web Server, etc. Groups are Cinnamon, Mate, Sound and Video, etc.
  • yum groupinfo "Cinnamon Desktop" => provides more info about this DE (Desktop Env) pkg. 
  • sudo yum groupinstall "GNOME desktop" => installs GNOME3 DE
  • sudo yum groupremove "Security Tools" => removes this group named "security tools"

FIXME: yum details FIXME