Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele Package Management on Servers | Configuration, Networking, and DevOps Essentials
Linux for DevOps Engineer

bookPackage Management on Servers

Package Management on Servers

Efficient package management is a core skill for any DevOps engineer working with Linux servers. Package managers help you install, update, configure, and remove software in a consistent and secure way. By mastering package management, you ensure your servers remain up-to-date, stable, and secure, while reducing manual errors and improving automation. Understanding how to manage packages is essential for maintaining reliable infrastructure and supporting seamless application deployments.

Overview of Package Managers

Package managers help you install, update, and remove software on Linux systems. They automate software management, ensuring you get the correct versions and dependencies for your operating system.

apt: Advanced Package Tool

  • Used on Debian-based distributions such as Ubuntu and Debian;
  • Handles .deb packages, which are native to these systems;
  • Example: to install nginx, run sudo apt install nginx;
  • Manages dependencies automatically and retrieves packages from online repositories.

yum: Yellowdog Updater, Modified

  • Used on older Red Hat-based distributions such as CentOS 7 and RHEL 7;
  • Handles .rpm packages, which are native to Red Hat systems;
  • Example: to install nginx, run sudo yum install nginx;
  • Supports repository management and can handle group installations (multiple related packages together).

dnf: Dandified Yum

  • Successor to yum on newer Red Hat-based distributions such as Fedora, CentOS 8, and RHEL 8;
  • Also manages .rpm packages but with improved performance and dependency resolution;
  • Example: to install nginx, run sudo dnf install nginx;
  • Offers better error handling, faster operations, and enhanced security features compared to yum.

Key Differences

  • Distribution compatibility: apt is for Debian-based systems, while yum and dnf are for Red Hat-based systems.
  • Performance: dnf offers faster and more reliable operations than yum.
  • Syntax: Commands are similar but not identical; always use the package manager designed for your system.

Real-World Usage

When managing a server running Ubuntu, you use apt to keep software up to date. On a CentOS 7 server, you rely on yum. For CentOS 8 or Fedora, you switch to dnf for improved speed and reliability. Always choose the package manager that matches your Linux distribution to ensure smooth software management.

Installing Software with Package Managers

Package managers make it easy to install, update, and remove software on Linux servers. The most common tools are apt, yum, and dnf. Each tool is used on different Linux distributions, but they all simplify software management by handling dependencies and automating installations.

Common Package Managers

  • apt: Used on Debian-based systems like Ubuntu;
  • yum: Used on older Red Hat-based systems like CentOS 7;
  • dnf: Used on newer Red Hat-based systems like CentOS 8, Fedora, and RHEL 8.

Command Structure Explained

Every package manager command follows a similar structure:

<package_manager> install <package_name>

  • <package_manager>: The tool you are using (apt, yum, or dnf);
  • install: The action you want to perform (installing software);
  • <package_name>: The name of the software package you want to install.

Example Commands

  • To install nginx on Ubuntu:

    sudo apt install nginx
    
    • sudo: Runs the command with administrator privileges;
    • apt: The package manager for Ubuntu;
    • install: Tells apt to install a package;
    • nginx: The package you want to install.
  • To install nginx on CentOS 7:

    sudo yum install nginx
    
    • yum: The package manager for CentOS 7;
    • The rest of the command is the same as above.
  • To install nginx on CentOS 8 or Fedora:

    sudo dnf install nginx
    
    • dnf: The package manager for CentOS 8 and newer Red Hat-based systems.

Real-World Scenario

Suppose you need to set up a web server for a new project. You decide to use nginx because it is lightweight and fast. On your Ubuntu server, you run:

sudo apt install nginx

This command downloads and installs nginx along with any required dependencies. After installation, you can start configuring your web server immediately.

Key Points

  • Always use sudo to ensure you have the necessary permissions;
  • The package name must match the name in your distribution’s repositories;
  • Package managers automatically resolve dependencies, saving you time and effort.

Using package managers streamlines software installation and ensures your server remains stable and secure.

Updating Software and System Packages

Keeping your server software up to date is critical for security, stability, and access to new features. Linux distributions provide package managers to help you update and upgrade software efficiently. The specific commands you use depend on your distribution.

Common Package Management Commands

  • apt update: Refreshes the list of available packages and their versions from repositories; does not install or upgrade any packages.
  • apt upgrade: Installs the newest versions of all currently installed packages based on the latest repository information; does not remove or install new packages.
  • yum update: Updates all packages to the latest available versions; used on older Red Hat-based distributions like CentOS 7.
  • dnf upgrade: Upgrades all packages to their latest versions; used on newer Red Hat-based distributions such as Fedora and CentOS 8+.

Example Workflow

On an Ubuntu server:

sudo apt update
sudo apt upgrade

On a CentOS 7 server:

sudo yum update

On a Fedora or CentOS 8+ server:

sudo dnf upgrade

Always review the list of packages to be updated before confirming, especially on production systems. Regular updates help protect your system from vulnerabilities and ensure you have the latest bug fixes.

Removing Software Packages

You often need to remove software from your Linux server to free up space, resolve conflicts, or maintain security. The commands you use depend on the Linux distribution:

  • Debian/Ubuntu: Use apt remove;
  • Red Hat/CentOS/Fedora: Use yum remove.

Using apt remove

On Debian-based systems, run:

sudo apt remove package-name

This command uninstalls the specified package but leaves behind its configuration files. If you want to remove configuration files as well, use apt purge instead.

Using yum remove

On Red Hat-based systems, use:

sudo yum remove package-name

This command removes the package and any unused dependencies that were installed with it.

Impact on System and Dependencies

  • Dependency Removal: Both apt remove and yum remove will attempt to remove packages that are no longer needed by any other installed software;
  • Configuration Files: apt remove keeps configuration files by default, so custom settings may persist; yum remove generally deletes all files related to the package;
  • Broken Dependencies: If you remove a package that other software depends on, those applications may stop working or fail to update properly;
  • Disk Space: Removing unnecessary packages helps free up disk space and reduces the attack surface of your server.

Always review the list of packages that will be removed before confirming, especially on production servers, to prevent accidental disruption of critical services.

question mark

Which package manager is primarily used on Debian-based Linux distributions?

Select the correct answer

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 3. Luku 3

Kysy tekoälyä

expand

Kysy tekoälyä

ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

bookPackage Management on Servers

Pyyhkäise näyttääksesi valikon

Package Management on Servers

Efficient package management is a core skill for any DevOps engineer working with Linux servers. Package managers help you install, update, configure, and remove software in a consistent and secure way. By mastering package management, you ensure your servers remain up-to-date, stable, and secure, while reducing manual errors and improving automation. Understanding how to manage packages is essential for maintaining reliable infrastructure and supporting seamless application deployments.

Overview of Package Managers

Package managers help you install, update, and remove software on Linux systems. They automate software management, ensuring you get the correct versions and dependencies for your operating system.

apt: Advanced Package Tool

  • Used on Debian-based distributions such as Ubuntu and Debian;
  • Handles .deb packages, which are native to these systems;
  • Example: to install nginx, run sudo apt install nginx;
  • Manages dependencies automatically and retrieves packages from online repositories.

yum: Yellowdog Updater, Modified

  • Used on older Red Hat-based distributions such as CentOS 7 and RHEL 7;
  • Handles .rpm packages, which are native to Red Hat systems;
  • Example: to install nginx, run sudo yum install nginx;
  • Supports repository management and can handle group installations (multiple related packages together).

dnf: Dandified Yum

  • Successor to yum on newer Red Hat-based distributions such as Fedora, CentOS 8, and RHEL 8;
  • Also manages .rpm packages but with improved performance and dependency resolution;
  • Example: to install nginx, run sudo dnf install nginx;
  • Offers better error handling, faster operations, and enhanced security features compared to yum.

Key Differences

  • Distribution compatibility: apt is for Debian-based systems, while yum and dnf are for Red Hat-based systems.
  • Performance: dnf offers faster and more reliable operations than yum.
  • Syntax: Commands are similar but not identical; always use the package manager designed for your system.

Real-World Usage

When managing a server running Ubuntu, you use apt to keep software up to date. On a CentOS 7 server, you rely on yum. For CentOS 8 or Fedora, you switch to dnf for improved speed and reliability. Always choose the package manager that matches your Linux distribution to ensure smooth software management.

Installing Software with Package Managers

Package managers make it easy to install, update, and remove software on Linux servers. The most common tools are apt, yum, and dnf. Each tool is used on different Linux distributions, but they all simplify software management by handling dependencies and automating installations.

Common Package Managers

  • apt: Used on Debian-based systems like Ubuntu;
  • yum: Used on older Red Hat-based systems like CentOS 7;
  • dnf: Used on newer Red Hat-based systems like CentOS 8, Fedora, and RHEL 8.

Command Structure Explained

Every package manager command follows a similar structure:

<package_manager> install <package_name>

  • <package_manager>: The tool you are using (apt, yum, or dnf);
  • install: The action you want to perform (installing software);
  • <package_name>: The name of the software package you want to install.

Example Commands

  • To install nginx on Ubuntu:

    sudo apt install nginx
    
    • sudo: Runs the command with administrator privileges;
    • apt: The package manager for Ubuntu;
    • install: Tells apt to install a package;
    • nginx: The package you want to install.
  • To install nginx on CentOS 7:

    sudo yum install nginx
    
    • yum: The package manager for CentOS 7;
    • The rest of the command is the same as above.
  • To install nginx on CentOS 8 or Fedora:

    sudo dnf install nginx
    
    • dnf: The package manager for CentOS 8 and newer Red Hat-based systems.

Real-World Scenario

Suppose you need to set up a web server for a new project. You decide to use nginx because it is lightweight and fast. On your Ubuntu server, you run:

sudo apt install nginx

This command downloads and installs nginx along with any required dependencies. After installation, you can start configuring your web server immediately.

Key Points

  • Always use sudo to ensure you have the necessary permissions;
  • The package name must match the name in your distribution’s repositories;
  • Package managers automatically resolve dependencies, saving you time and effort.

Using package managers streamlines software installation and ensures your server remains stable and secure.

Updating Software and System Packages

Keeping your server software up to date is critical for security, stability, and access to new features. Linux distributions provide package managers to help you update and upgrade software efficiently. The specific commands you use depend on your distribution.

Common Package Management Commands

  • apt update: Refreshes the list of available packages and their versions from repositories; does not install or upgrade any packages.
  • apt upgrade: Installs the newest versions of all currently installed packages based on the latest repository information; does not remove or install new packages.
  • yum update: Updates all packages to the latest available versions; used on older Red Hat-based distributions like CentOS 7.
  • dnf upgrade: Upgrades all packages to their latest versions; used on newer Red Hat-based distributions such as Fedora and CentOS 8+.

Example Workflow

On an Ubuntu server:

sudo apt update
sudo apt upgrade

On a CentOS 7 server:

sudo yum update

On a Fedora or CentOS 8+ server:

sudo dnf upgrade

Always review the list of packages to be updated before confirming, especially on production systems. Regular updates help protect your system from vulnerabilities and ensure you have the latest bug fixes.

Removing Software Packages

You often need to remove software from your Linux server to free up space, resolve conflicts, or maintain security. The commands you use depend on the Linux distribution:

  • Debian/Ubuntu: Use apt remove;
  • Red Hat/CentOS/Fedora: Use yum remove.

Using apt remove

On Debian-based systems, run:

sudo apt remove package-name

This command uninstalls the specified package but leaves behind its configuration files. If you want to remove configuration files as well, use apt purge instead.

Using yum remove

On Red Hat-based systems, use:

sudo yum remove package-name

This command removes the package and any unused dependencies that were installed with it.

Impact on System and Dependencies

  • Dependency Removal: Both apt remove and yum remove will attempt to remove packages that are no longer needed by any other installed software;
  • Configuration Files: apt remove keeps configuration files by default, so custom settings may persist; yum remove generally deletes all files related to the package;
  • Broken Dependencies: If you remove a package that other software depends on, those applications may stop working or fail to update properly;
  • Disk Space: Removing unnecessary packages helps free up disk space and reduces the attack surface of your server.

Always review the list of packages that will be removed before confirming, especially on production servers, to prevent accidental disruption of critical services.

question mark

Which package manager is primarily used on Debian-based Linux distributions?

Select the correct answer

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 3. Luku 3
some-alt