Skip to main content

Command Palette

Search for a command to run...

How to Install Package on Linux

Published
6 min readView as Markdown

Installing packages on Linux is a fundamental skill that every user should know. Whether you're setting up a new system or adding software to your existing setup, understanding how to install packages helps you get the most out of your Linux experience. In this guide, I'll walk you through the most common methods to install packages on Linux, making it easy for you to manage software efficiently.

You might be wondering which method suits your Linux distribution or how to handle different package formats. Don't worry! We'll cover everything from using popular package managers like APT and YUM to installing software from source or using universal package formats. By the end, you'll feel confident managing software on your Linux system.

Understanding Linux Package Management

Linux distributions use package managers to simplify software installation, updates, and removal. These tools handle dependencies and ensure your system stays stable. Different Linux distros use different package managers, but the goal is the same: to make software management easy.

Here are some common package managers you’ll encounter:

  • APT (Advanced Package Tool): Used by Debian, Ubuntu, and derivatives.
  • YUM/DNF: Used by Fedora, CentOS, and Red Hat.
  • Pacman: Used by Arch Linux.
  • Zypper: Used by openSUSE.

Each package manager works with specific package formats like .deb for Debian-based systems or .rpm for Red Hat-based systems.

Installing Packages Using APT on Debian and Ubuntu

APT is one of the most popular package managers. It handles .deb packages and is known for its ease of use.

Steps to Install a Package with APT

  1. Update Package List:
    Always start by updating your package list to get the latest versions.

    sudo apt update
    
  2. Install the Package:
    Use the install command followed by the package name.

    sudo apt install package-name
    
  3. Verify Installation:
    Check if the package installed correctly by running its command or checking its version.

    package-name --version
    

Example: Installing Git

sudo apt update
sudo apt install git
git --version

APT also allows you to install multiple packages at once:

sudo apt install git curl vim

Installing Packages Using YUM or DNF on Fedora and Red Hat

Fedora and Red Hat use YUM or its successor DNF for package management. These tools work with .rpm packages.

Using DNF to Install Packages

DNF is the modern replacement for YUM and is preferred on newer systems.

  1. Update Repository Metadata:

    sudo dnf check-update
    
  2. Install the Package:

    sudo dnf install package-name
    
  3. Confirm Installation:

    package-name --version
    

Example: Installing Vim

sudo dnf check-update
sudo dnf install vim
vim --version

YUM commands are similar but may be used on older systems:

sudo yum install package-name

Using Pacman on Arch Linux

Arch Linux uses Pacman, a powerful package manager that handles .pkg.tar.zst packages.

Installing Packages with Pacman

  1. Update Package Database:

    sudo pacman -Sy
    
  2. Install the Package:

    sudo pacman -S package-name
    
  3. Verify Installation:

    package-name --version
    

Example: Installing Firefox

sudo pacman -Sy
sudo pacman -S firefox
firefox --version

Pacman also supports installing multiple packages at once:

sudo pacman -S git curl wget

Installing Packages Using Zypper on openSUSE

openSUSE uses Zypper as its package manager, which works with .rpm packages.

Steps to Install Packages with Zypper

  1. Refresh Repositories:

    sudo zypper refresh
    
  2. Install the Package:

    sudo zypper install package-name
    
  3. Check Installation:

    package-name --version
    

Example: Installing Nano Editor

sudo zypper refresh
sudo zypper install nano
nano --version

Installing Packages from .deb or .rpm Files Manually

Sometimes, you may download a package file directly from a website. You can install these manually.

Installing .deb Packages

Use dpkg to install .deb files:

sudo dpkg -i package-file.deb

If dependencies are missing, fix them with:

sudo apt-get install -f

Installing .rpm Packages

Use rpm to install .rpm files:

sudo rpm -i package-file.rpm

If you encounter dependency issues, use:

sudo dnf install package-file.rpm

or

sudo yum install package-file.rpm

depending on your system.

Using Universal Package Formats: Snap and Flatpak

To avoid dependency issues and support multiple distributions, universal package formats like Snap and Flatpak are popular.

Installing Snap Packages

Snap packages are containerized and work on many Linux distros.

  1. Install Snapd (if not installed):

    sudo apt install snapd
    
  2. Install a Snap Package:

    sudo snap install package-name
    
  3. Example: Installing VLC Media Player

    sudo snap install vlc
    

Installing Flatpak Packages

Flatpak is another universal package system.

  1. Install Flatpak:

    sudo apt install flatpak
    
  2. Add Flathub Repository:

    flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
    
  3. Install a Flatpak Package:

    flatpak install flathub package-name
    
  4. Example: Installing Spotify

    flatpak install flathub com.spotify.Client
    

Installing Software from Source Code

Sometimes, software isn't available as a package. You can compile it from source.

Basic Steps to Compile Software

  1. Download the Source Code:
    Usually from the project's website or GitHub.

  2. Extract the Archive:

    tar -xvf package.tar.gz
    cd package-directory
    
  3. Configure the Build:

    ./configure
    
  4. Compile the Software:

    make
    
  5. Install the Software:

    sudo make install
    

Notes

  • You may need development tools like build-essential or gcc.
  • Check the README or INSTALL files for specific instructions.

Tips for Managing Packages on Linux

  • Keep your system updated: Regularly update your package lists and upgrade installed packages.
  • Use official repositories: They are safer and more stable.
  • Check package dependencies: Package managers usually handle this, but manual installs may require extra care.
  • Remove unused packages: Use commands like sudo apt autoremove to clean up.
  • Use package search: Commands like apt search package-name help find software.

Conclusion

Installing packages on Linux is easier than it seems once you understand the tools available. Whether you use APT, YUM, Pacman, or universal formats like Snap and Flatpak, each method has its place. Knowing how to install from source adds flexibility when packages aren't available.

By mastering these techniques, you can customize your Linux system to fit your needs perfectly. Remember to keep your system updated and use trusted sources to ensure security and stability. Now, you’re ready to install any package on your Linux system with confidence.

FAQs

How do I update all installed packages on Linux?

You can update all packages using your package manager. For example, on Debian/Ubuntu, run sudo apt update followed by sudo apt upgrade. On Fedora, use sudo dnf upgrade.

What is the difference between Snap and Flatpak?

Both are universal package formats that work across Linux distros. Snap is developed by Canonical and uses a centralized store, while Flatpak is community-driven and uses Flathub as its main repository.

Can I install Windows software on Linux?

Not directly. However, you can use compatibility layers like Wine or virtualization tools to run some Windows applications on Linux.

How do I remove a package on Linux?

Use your package manager's remove command. For example, sudo apt remove package-name on Debian-based systems or sudo dnf remove package-name on Fedora.

What should I do if a package installation fails due to missing dependencies?

Try running the package manager's fix command, like sudo apt-get install -f on Debian-based systems, which attempts to fix broken dependencies automatically.

More from this blog

L

LinuxBloke | Linux Tips, Tricks & Troubleshooting

672 posts