Software Installation and Updates

LinuxBeginner
Practice Now

Introduction

Welcome to the world of Linux package management! One of the most powerful features of Linux is its systematic approach to installing, updating, and removing software. On Debian-based systems like Ubuntu, the primary tool for this is the Advanced Package Tool, or apt.

In this lab, you will get hands-on experience with the essential apt commands. You will learn the complete lifecycle of managing a software package: updating your system's package information, installing a new application, upgrading existing software, checking what's installed, and finally, removing an application. We will use vim, a popular command-line text editor, as our example package.

By the end of this lab, you will be comfortable with the basic software management tasks that every Linux user needs to know.

Update Repositories with apt update Command

In this step, you will learn how to update your system's local package index. This is a crucial first step before installing or upgrading any software.

The apt update command doesn't upgrade any software. Instead, it downloads the latest package information (like version numbers and dependencies) from the software repositories configured on your system. This ensures that when you decide to install or upgrade, you are getting the most recent and correct versions available.

Since updating the package list requires administrative privileges, you must use the sudo command. Run the following command in your terminal:

sudo apt update

You will see a series of lines as apt connects to various web addresses to fetch the package lists. The output will look something like this:

Hit:1 http://archive.ubuntu.com/ubuntu jammy InRelease
Get:2 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [119 kB]
Get:3 http://security.ubuntu.com/ubuntu jammy-security InRelease [119 kB]
...
Fetched 3,134 kB in 2s (1,835 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
All packages are up to date.

Now your system knows about all the latest software available.

Install vim with apt install vim Command

In this step, you will install a new software package, vim. vim is a highly configurable and powerful text editor that is very popular among developers and system administrators.

The command to install a package is apt install, followed by the name of the package. Like apt update, this action requires administrative privileges, so you'll need sudo.

Execute the following command to install vim:

sudo apt install vim

The system will first calculate the dependencies (other packages that vim needs to function) and then show you a list of all the packages that will be installed. It will ask for your confirmation.

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  vim-runtime
Suggested packages:
  ctags vim-doc vim-scripts
The following NEW packages will be installed:
  vim vim-runtime
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 7,578 kB of archives.
After this operation, 36.3 MB of additional disk space will be used.
Do you want to continue? [Y/n]

Type Y and press Enter to proceed with the installation. apt will then download and install vim and its dependencies.

Upgrade Packages with apt upgrade -y Command

In this step, you will upgrade all the installed packages on your system to their latest versions. While apt update refreshes the package list, apt upgrade actually downloads and installs the newer versions of the software.

Keeping your system upgraded is important for security and stability, as upgrades often include bug fixes and patches for vulnerabilities.

The command is apt upgrade. We will add the -y flag, which automatically answers "yes" to any confirmation prompts. This is very useful for non-interactive situations, like in scripts, or when you are certain you want to proceed with the upgrade.

Run the following command in your terminal:

sudo apt upgrade -y

The upgrade process may take some time depending on how many packages need to be upgraded and your internet connection speed. You will see output showing the packages being downloaded and installed:

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done
The following packages will be upgraded:
  package1 package2 package3
3 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 1,234 kB of archives.
After this operation, 56.7 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 package1 amd64 1.2.3-1 [123 kB]
...
Fetched 1,234 kB in 5s (246 kB/s)
(Reading database ... 123456 files and directories currently installed.)
Preparing to unpack .../package1_1.2.3-1_amd64.deb ...
Unpacking package1 (1.2.3-1) over (1.2.2-1) ...
Setting up package1 (1.2.3-1) ...
...
Processing triggers for package1 (1.2.3-1) ...

Please be patient and wait for the upgrade process to complete. Once finished, all your installed software will be running the latest version available in the repositories you updated in Step 1.

List Installed Packages with dpkg -l | grep vim Command

In this step, you will learn how to check which packages are installed on your system and how to search for a specific one. For this, we will use dpkg, the lower-level package manager that apt is built upon, combined with the grep command.

The command dpkg -l lists all packages known to the system. This list can be very long, so it's often more useful to filter it. We can do this by "piping" the output to another command. The pipe symbol | takes the output of the command on its left and uses it as the input for the command on its right.

We will pipe the output of dpkg -l to grep vim, which will filter the list and show only the lines containing the word "vim".

Run this command:

dpkg -l | grep vim

The output will show you details about the vim package and any other related packages you have installed:

ii  vim                                    2:8.2.3995-1ubuntu2.24                  amd64        Vi IMproved - enhanced vi editor
ii  vim-common                             2:8.2.3995-1ubuntu2.24                  all          Vi IMproved - Common files
ii  vim-gtk                                2:8.2.3995-1ubuntu2.24                  all          Vi IMproved - enhanced vi editor (dummy package)
ii  vim-gtk3                               2:8.2.3995-1ubuntu2.24                  amd64        Vi IMproved - enhanced vi editor - with GTK3 GUI
ii  vim-gui-common                         2:8.2.3995-1ubuntu2.24                  all          Vi IMproved - Common GUI files
ii  vim-runtime                            2:8.2.3995-1ubuntu2.24                  all          Vi IMproved - Runtime files

The ii at the beginning of the line indicates that the package is installed and was configured correctly. This is a quick way to confirm that your installation in Step 2 was successful.

Remove Package with apt remove vim Command

In this step, you will complete the package management lifecycle by removing the vim package you installed earlier.

The command to uninstall a package is apt remove, followed by the package name. This command will remove the package's binary files but may leave behind some configuration files. If you wanted to remove the configuration files as well, you would use apt purge. For this lab, apt remove is sufficient.

Just like installing, removing a package requires sudo privileges. Execute the following command:

sudo apt remove vim

The system will show you which packages are going to be removed and ask for your confirmation.

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:
  vim
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 583 kB of disk space will be freed.
Do you want to continue? [Y/n]

Type Y and press Enter to confirm the removal. apt will then proceed to uninstall the package. After this, the vim command will no longer be available on your system.

Summary

Congratulations on completing this lab! You have successfully learned the fundamental commands for managing software on a Debian-based Linux system like Ubuntu.

In this lab, you practiced the full lifecycle of package management:

  • sudo apt update: To synchronize your local package index with the online repositories.
  • sudo apt install vim: To install a new application.
  • sudo apt upgrade -y: To upgrade all installed packages to their latest versions.
  • dpkg -l | grep vim: To list installed packages and search for a specific one.
  • sudo apt remove vim: To uninstall an application.

These commands are the bedrock of system administration and daily use on Linux. With this knowledge, you are now well-equipped to manage the software on your own Linux systems.