install Command in Linux

Introduction to Linux Package Management

This hands-on lab provides a comprehensive guide to installing Linux packages utilizing essential package management commands, specifically apt-get, apt, and snap. This tutorial covers crucial steps such as updating package repositories, installing desired packages, and interpreting command outputs. Furthermore, this lab explores alternative package management tools and their suitable application scenarios, ensuring a solid grasp of package installation within Linux environments. Perfect for any aspiring systemadmin!

Installing Linux Packages with apt-get

In this section, you'll discover how to install Linux packages using the versatile apt-get command. Renowned for its robust capabilities, apt-get stands as a primary tool for package management on Debian and Ubuntu-based Linux distributions.

Firstly, it's crucial to update your package lists, guaranteeing you have access to the most recent details regarding available packages:

sudo apt-get update

Example output:

Hit:1 http://archive.ubuntu.com/ubuntu jammy InRelease
Get:2 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [114 kB]
Get:3 http://archive.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
Get:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease [99.8 kB]
Fetched 324 kB in 1s (324 kB/s)
Reading package lists... Done

Now, let's proceed to install a package using apt-get install. We will install the tree package, a practical command-line utility that visualizes directory structures in a hierarchical tree format. This is incredibly helpful for systemadmin tasks.

sudo apt update
sudo apt-get install -y tree

Example output:

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libglib2.0-0 libicu70 libncurses6 libpcre2-8-0 libreadline8 libstdc++6 libtinfo6 zlib1g
Suggested packages:
  rsync
The following NEW packages will be installed:
  libglib2.0-0 libicu70 libncurses6 libpcre2-8-0 libreadline8 libstdc++6 libtinfo6 tree zlib1g
0 upgraded, 9 newly installed, 0 to remove and 0 not upgraded.
Need to get 3,010 kB of archives.
After this operation, 11.8 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://archive.ubuntu.com/ubuntu jammy/main amd64 libglib2.0-0 amd64 2.72.1-1ubuntu1 [1,264 kB]
...
Fetched 3,010 kB in 1s (3,010 kB/s)
Selecting previously unselected package libglib2.0-0:amd64.
(Reading database ... 17869 files and directories currently installed.)
Preparing to unpack .../libglib2.0-0_2.72.1-1ubuntu1_amd64.deb ...
Unpacking libglib2.0-0:amd64 (2.72.1-1ubuntu1) ...
...
Setting up tree (1.8.0-1ubuntu1) ...
Processing triggers for libc-bin (2.35-0ubuntu3) ...

The apt-get install command downloads the package, resolves any necessary dependencies, and proceeds to install everything onto your Linux system.

You can also uninstall packages using the apt-get remove command:

sudo apt-get remove -y tree

Example output:

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:
  tree
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 116 kB of disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 17874 files and directories currently installed.)
Removing tree (1.8.0-1ubuntu1) ...
Processing triggers for man-db (2.10.2-1) ...

The apt-get remove command uninstalls the designated package from your system, freeing up resources.

Installing Linux Packages with apt

In this segment, you'll explore installing Linux packages using the apt command. Serving as a more user-friendly front-end for apt-get, the apt command offers a streamlined and intuitive approach to package management. It's a favorite amongst systemadmins for its ease of use.

Let's begin by updating the package lists once more:

sudo apt update

Example output:

Hit:1 http://archive.ubuntu.com/ubuntu jammy InRelease
Get:2 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [114 kB]
Get:3 http://archive.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
Get:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease [99.8 kB]
Fetched 324 kB in 1s (324 kB/s)
Reading package lists... Done

Now, let's install the htop package, a widely-used interactive process viewer and system monitoring tool:

sudo apt install -y htop

Example output:

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libncursesw6 libsensors-config libsensors5 libstdc++6
Suggested packages:
  lm-sensors
The following NEW packages will be installed:
  htop libncursesw6 libsensors-config libsensors5 libstdc++6
0 upgraded, 5 newly installed, 0 to remove and 0 not upgraded.
Need to get 390 kB of archives.
After this operation, 1,493 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://archive.ubuntu.com/ubuntu jammy/main amd64 libncursesw6 amd64 6.3-2 [115 kB]
...
Fetched 390 kB in 1s (390 kB/s)
Selecting previously unselected package libncursesw6:amd64.
(Reading database ... 17874 files and directories currently installed.)
Preparing to unpack .../libncursesw6_6.3-2_amd64.deb ...
Unpacking libncursesw6:amd64 (6.3-2) ...
...
Setting up htop (3.0.5-1) ...
Processing triggers for man-db (2.10.2-1) ...

Similar to apt-get, the apt install command manages dependencies, downloads the package, and installs it on your system.

Removing packages can also be done via the apt remove command:

sudo apt remove -y htop

Example output:

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:
  htop
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 1,493 kB of disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 17879 files and directories currently installed.)
Removing htop (3.0.5-1) ...
Processing triggers for man-db (2.10.2-1) ...

The apt remove command serves to uninstall the specified package from your Linux environment.

Installing Linux Packages with Snap

This section focuses on installing Linux packages through the Snap package manager. Snap provides a containerized software packaging and deployment system created by Canonical, primarily for Ubuntu but compatible with other Linux distributions. Snaps are useful when you need a consistent runtime environment, regardless of the underlying OS.

First, verify that the Snap service is up and running:

sudo systemctl status snapd

Example output:

● snapd.service - Snap Daemon
     Loaded: loaded (/lib/systemd/system/snapd.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2023-04-21 07:15:09 UTC; 1min 30s ago
       Docs: https://snapcraft.io
   Main PID: 1216 (snapd)
      Tasks: 10 (limit: 4915)
     Memory: 33.2M
        CPU: 375ms
     CGroup: /system.slice/snapd.service
             └─1216 /usr/lib/snapd/snapd

Apr 21 07:15:09 lab-ubuntu-22.04 systemd[1]: Started Snap Daemon.

Now, install the vlc package utilizing the Snap command:

sudo snap install vlc

Example output:

vlc 3.0.18 from 'videolan' installed

The snap install command handles the download and installation of the Snap package onto your system.

Packages can also be removed using the snap remove command:

sudo snap remove vlc

Example output:

vlc removed

The snap remove command uninstalls the designated Snap package.

Conclusion

This lab has equipped you with the knowledge to install Linux packages effectively using apt-get, a powerful tool for package management in Ubuntu and similar Linux distributions. You learned to update package lists for the latest available information and successfully installed the tree package for visualizing directory structures. This is a common task for any systemadmin.

Furthermore, you explored the apt command, a modern and user-friendly alternative to apt-get. Finally, you gained experience with the Snap package manager, representing a unique approach to software installation and management on Linux, offering sandboxed environments and consistent dependencies. Understanding these methods is crucial for any Linux user, especially those aspiring to become systemadmin professionals. Remember to always run commands as root or use sudo where necessary for package management.

400+ Linux Commands