Software Installation on Linux

LinuxLinuxBeginner
Practice Now

Introduction

This lab will introduce you to the basics of software installation on Ubuntu Linux systems. You'll learn how to use package management tools like apt and dpkg to install, update, and remove software packages. This knowledge is essential for managing software on Linux systems effectively.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/BasicSystemCommandsGroup(["`Basic System Commands`"]) linux(("`Linux`")) -.-> linux/PackagesandSoftwaresGroup(["`Packages and Softwares`"]) linux(("`Linux`")) -.-> linux/FileandDirectoryManagementGroup(["`File and Directory Management`"]) linux(("`Linux`")) -.-> linux/UserandGroupManagementGroup(["`User and Group Management`"]) linux/BasicSystemCommandsGroup -.-> linux/tree("`Directory Tree Display`") linux/PackagesandSoftwaresGroup -.-> linux/wget("`Non-interactive Downloading`") linux/PackagesandSoftwaresGroup -.-> linux/apt("`Package Handling`") linux/FileandDirectoryManagementGroup -.-> linux/which("`Command Locating`") linux/UserandGroupManagementGroup -.-> linux/sudo("`Privilege Granting`") subgraph Lab Skills linux/tree -.-> lab-18005{{"`Software Installation on Linux`"}} linux/wget -.-> lab-18005{{"`Software Installation on Linux`"}} linux/apt -.-> lab-18005{{"`Software Installation on Linux`"}} linux/which -.-> lab-18005{{"`Software Installation on Linux`"}} linux/sudo -.-> lab-18005{{"`Software Installation on Linux`"}} end

Update the Package List

Before installing new software, it's crucial to update the package list. This ensures you have the latest information about available packages and their versions.

  1. Open a terminal. You should be in the /home/labex/project directory by default. If not, don't worry - the commands we'll use work from any directory.

  2. Run the following command to update the package list:

    sudo apt update

    Let's break this down:

    • sudo: This gives you temporary administrative (superuser) privileges.
    • apt: This is the package management command we're using.
    • update: This tells apt to update the package list.
  3. You might be prompted to enter your password. Type it in and press Enter. Note that the password won't be visible as you type - this is a security feature, not a malfunction.

  4. You'll see a lot of text scrolling by. This is normal! The system is checking various repositories (online software sources) for updates.

  5. When it's done, you'll see a message like "Reading package lists... Done". This means the update was successful.

Install a Package Using apt

Now that we've updated our package list, let's install a package using the apt command.

  1. We'll install the w3m package, which is a text-based web browser. Run the following command:

    sudo apt install w3m -y

    Here's what this command does:

    • sudo: Again, we need superuser privileges to install software.
    • apt install: This tells apt we want to install a package.
    • w3m: This is the name of the package we want to install.
    • -y: This flag automatically answers "yes" to any prompts during the installation process.
  2. You'll see output showing the progress of the installation. Don't worry if you see messages about additional packages being installed - these are dependencies that w3m needs to function.

  3. Once the installation is finished, you can verify that w3m is installed by running:

    w3m -version

    This should display the version information for w3m. If you see this, congratulations! You've successfully installed a package.

Sometimes you might not know the exact name of the package you want to install. In such cases, you can search for packages using apt-cache search.

  1. Let's search for packages related to "text editor". Run the following command:

    apt-cache search "text editor"

    This command searches the package descriptions for the words "text" and "editor".

  2. This will display a list of packages that match the search term. Each line will show a package name followed by a brief description.

  3. You might see a lot of results. Don't worry, this is normal! Linux has many text editors available. For example, you might see something like:

    nano - small, friendly text editor inspired by Pico
    vim - Vi IMproved - enhanced vi editor
  4. If you want to narrow down your search, you can use grep. For example, to find only GUI text editors:

    apt-cache search "text editor" | grep -i gui

    The | grep -i gui part filters the results to only show lines containing "gui" (case-insensitive).

Remove a Package

If you no longer need a package, you can remove it using apt remove.

  1. Let's remove the w3m package we installed earlier. Run the following command:

    sudo apt remove w3m -y

    This command will remove the w3m package, but it will leave its configuration files intact.

  2. If you want to remove the configuration files as well, you can use apt purge instead:

    sudo apt purge w3m -y

    Be careful with purge - it completely removes all traces of the package, including configuration files that you might want to keep if you plan to reinstall the package later.

  3. After removing the package, it's a good idea to clean up any leftover dependencies that are no longer needed:

    sudo apt autoremove -y

    This command removes packages that were automatically installed to satisfy dependencies for other packages and are now no longer needed.

Install a Package Using a .deb File

In this step, we'll install the tree package using a .deb file. This process demonstrates how to install software that might not be available through the standard package repositories.

  1. First, let's remove any existing installations of tree:

    cd /home/labex/project
    sudo apt remove tree -y
    sudo apt autoremove -y

    This ensures we're starting from a clean state.

  2. Now, let's download the .deb file for tree:

    Tips: Free users can not have access to the internet. tree_2.0.2-1_amd64.deb is already available in the /home/labex/project directory. You can skip this step.

    wget http://archive.ubuntu.com/ubuntu/pool/universe/t/tree/tree_2.0.2-1_amd64.deb

    This command downloads the .deb file to your current directory.

  3. Before we install, let's check the package information:

    dpkg -I tree_2.0.2-1_amd64.deb

    This will show you details about the package, including its dependencies.

  4. Now, let's install the package using dpkg:

    sudo dpkg -i tree_2.0.2-1_amd64.deb

    If there are no dependency issues, this should install the package successfully.

  5. If you see any error messages about unmet dependencies, you can resolve them using:

    sudo apt -f install

    This command will install any missing dependencies.

  6. Verify the installation:

    tree --version

    This should display the version information for tree.

  7. To see the tree command in action, let's create a simple directory structure and use tree to display it:

    mkdir -p test/dir1/subdir test/dir2
    touch test/file1.txt test/dir1/file2.txt test/dir2/file3.txt
    tree test

    You should see a tree-like structure of the directories and files you just created.

  8. If you want to see more options for the tree command, you can view its manual page:

    man tree

    Press 'q' to exit the manual page.

This process demonstrates how to install a package from a .deb file, handle potential dependency issues, and verify the installation. The tree command is a useful tool for visualizing directory structures in the terminal.

Summary

In this lab, you've learned the basics of software installation on Ubuntu Linux. You've used apt to update the package list, install and remove packages, and search for packages. You've also learned how to use dpkg to install a .deb package file directly.

Here's a quick recap of the main commands we've learned:

  • sudo apt update: Update the package list
  • sudo apt install <package>: Install a package
  • apt-cache search <term>: Search for packages
  • sudo apt remove <package>: Remove a package
  • sudo apt purge <package>: Remove a package and its configuration files
  • sudo apt autoremove: Remove unnecessary dependencies
  • sudo dpkg -i <file.deb>: Install a .deb file

These skills will be essential as you continue to work with Linux systems, allowing you to manage software effectively. Remember, while we used simple packages like w3m and htop for this lab, the same principles apply to installing more complex software. Always make sure to keep your system updated and be cautious when installing packages from unknown sources.

Other Linux Tutorials you may like