Package management

  • In Linux operating systems there are couple of ways for installing a new software:

    1. Using package management software included in Linux distribution
    2. Downloading and extracting software package (usually in .tar.gz or similar format)
    3. Cloning Git repository to your computer
  • Usually software is in precompiled binary (can be used without further compiling)

  • If software is not yet compiled, it must be compiled from software source code

  • Two of the most common package types are

    • rpm (Red Hat Linux, Mandrake, SuSE)
    • deb (Debian GNU/Linux, Ubuntu)
  • Below is a table containing more information of different package types

Linux distribution Format Tool(s)
Debian .deb apt, apt-cache, apt-get, dpkg
Ubuntu .deb apt, apt-cache, apt-get, dpkg
CentOS .rpm yum
Fedora .rpm dnf
FreeBSD .txz make, pkg
  • Packages can be installed with certain limitations for all Linux distributions supporting compatible package management system
  • There are programs for making conversions between package types (for example .deb → .rpm)
    • Alien file converter

Package management in Ubuntu

  • Most people think Debian is the easiest Linux distribution to keep up-to-date
  • Since Ubuntu is based on Debian this opinion is valid also with Ubuntu package management (apt)
  • In Ubuntu packages are usually installed with APTITUDE or APT (Advanced Package Tool) programs
  • These programs use Debian's dpkg package system by default
  • In Debian-based distributions .deb is used as a package format, but APT can also be used with .rpm packages

APT package management

  • Available package list can be updated with the following command:
sudo apt update
  • This command retrieves the package information as well as necessary package dependencies from package repositories defined in /etc/apt/sources.list file
  • For example, if program that user wants to install cannot be found from default repositories, user needs to add that repository in sources.list and then rerun the apt update command
  • It is recommended to run apt update command before doing any package installation or upgrades to system since lists may change several times in a day
  • In order to check whether the installed packages can be upgraded, you can do this with the following command:
sudo apt upgrade
  • This command will also read /etc/apt/sources.list file and compare available package versions for installed ones
  • Command output will include all packages that could be upgraded
  • In addition, packages that are no longer needed will be listed
  • Single program can be installed using the following syntax:
sudo apt install package_name
  • In addition, APT installs all additional packages required during the installation of the package
  • Installed package can be removed with the following command:
sudo apt remove package_name
  • Removing package with this command does not remove configuration files used by the program
  • If configuration files should also be removed, apt purge command must be used
sudo apt purge package_name
  • Packages can be searched with apt search using the following syntax:
sudo apt search package_name
  • Command returns information about all packages in repository matching the given package_name
  • More accurate package information can be retrieved with the following command:
sudo apt show package_name

Compiling GNU program from source code

  • The task of a compiler is to compile 'plain language' source code into binary code understandable and executable by computers
  • This is called program compiling
  • Program can be compiled without any programming skills
  • The only requirement is that source code and compiler must be available
  • Why should you compile a program from source code?

    • Same installation method can be used in different Linux/Unix distributions
    • Automated compiling method requires only a littly more work than using a package management system
    • Additional features are required that may not be available with precompiled package distributed through package management system
    • The newest program versions are only available as source code packages
  • Below is an example of compiling a program from source code

  • Example: Install SQLite database program
  1. First let's install gcc compiler for Ubuntu
    testuser@ubuntu-pc:~$ sudo apt install build-essential
    
  2. Next let's download the source code package for the program
    testuser@
    ubuntu-pc:~$ wget https://www.sqlite.org/2019/sqlite-autoconf-3290000.tar.gz
    
  3. Extract the downloaded package
    testuser@ubuntu-pc:~$ tar xvf sqlite-autoconf-3290000.tar.gz
    
  4. Change your current working directory to the installation directory and sort out package dependencies
    testuser@ubuntu-pc:~$ cd sqlite-autoconf-3290000/
    testuser@ubuntu-pc:~/sqlite-autoconf-3290000$ sudo ./configure
    
  5. Compile program's binary files
    testuser@ubuntu-pc:~/sqlite-autoconf-3290000$ sudo make
    
  6. Install a program
    testuser@ubuntu-pc:~/sqlite-autoconf-3290000$ sudo make install
    
  7. Verify that program works
    testuser@ubuntu-pc:~/sqlite-autoconf-3290000$ sqlite3
    
  • Program can be closed with Ctrl + d