Linux install Command with Practical Examples

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn how to install Linux packages using various package management commands, including apt-get, apt, and snap. The lab covers the essential steps for updating package lists, installing new packages, and understanding the output of these commands. Additionally, the lab highlights alternative package management tools and their appropriate use cases, providing a comprehensive understanding of package installation on Linux systems.

Linux Commands Cheat Sheet


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/PackagesandSoftwaresGroup(["`Packages and Softwares`"]) linux(("`Linux`")) -.-> linux/UserandGroupManagementGroup(["`User and Group Management`"]) linux/PackagesandSoftwaresGroup -.-> linux/apt("`Package Handling`") linux/UserandGroupManagementGroup -.-> linux/sudo("`Privilege Granting`") subgraph Lab Skills linux/apt -.-> lab-422738{{"`Linux install Command with Practical Examples`"}} linux/sudo -.-> lab-422738{{"`Linux install Command with Practical Examples`"}} end

Install Linux Packages Using apt-get

In this step, you will learn how to install Linux packages using the apt-get command. The apt-get command is a powerful tool for managing packages on Ubuntu-based Linux distributions.

First, let's update the package lists to ensure we have the latest information about 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 install a package using apt-get install. We'll install the tree package, which is a command-line tool that displays the directory structure in a tree-like format:

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 and its dependencies, and then installs them on your system.

You can also remove 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 removes the specified package from your system.

Install Linux Packages Using apt

In this step, you will learn how to install Linux packages using the apt command. The apt command is a user-friendly interface for the apt-get command, providing a simpler and more intuitive way to manage packages.

Let's start by updating the package lists again:

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, which is a popular 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) ...

The apt install command downloads the package and its dependencies, and then installs them on your system.

You can also remove packages using 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 removes the specified package from your system.

Install Linux Packages Using Snap

In this step, you will learn how to install Linux packages using the Snap package manager. Snap is a containerized software packaging and deployment system developed by Canonical for Ubuntu and other Linux distributions.

First, let's ensure that the Snap service is 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, let's install the vlc package using the Snap command:

sudo snap install vlc

Example output:

vlc 3.0.18 from 'videolan' installed

The snap install command downloads and installs the specified Snap package on your system.

You can also remove packages using the snap remove command:

sudo snap remove vlc

Example output:

vlc removed

The snap remove command removes the specified Snap package from your system.

Summary

In this lab, you learned how to install Linux packages using the apt-get command, which is a powerful tool for managing packages on Ubuntu-based Linux distributions. You started by updating the package lists to ensure you have the latest information about available packages. Then, you installed the tree package, which is a command-line tool that displays the directory structure in a tree-like format.

You also learned how to install Linux packages using the apt command, which is a newer and more user-friendly package management tool compared to apt-get. Additionally, you explored the use of the Snap package manager, which provides a different approach to installing and managing software on Linux systems.

Linux Commands Cheat Sheet

Other Linux Tutorials you may like