Day 7 : Understanding package manager and systemctl

ยท

9 min read

Introduction:

A package manager in Linux streamlines software installation, ensuring efficient management. systemctl controls system services, simplifying their administration. Both are pivotal tools for effective Linux system maintenance.

What is a package manager in Linux?

In Linux, a package manager is a tool that helps you install, update, and manage software packages on your system. Think of it as a convenient way to handle the installation and maintenance of software, saving you from the hassle of manual downloads, dependencies, and configurations.

One of the most widely used package managers is apt for Debian-based distributions (like Ubuntu). Let me break down some common tasks using apt:

1. Installing Software:

To install a package, you simply use the apt install command. For example, let's install a text editor called nano:

sudo apt install nano

This command fetches the latest version of Nano and installs it on your system.

2. Updating Package Lists:

Before installing or upgrading software, it's good to update the package lists to get the latest information about available packages. Run:

sudo apt update

This command fetches the latest package information from the repositories.

3. Upgrading Installed Packages:

To upgrade your installed packages to the latest versions, use:

sudo apt upgrade

This command installs the latest versions of packages you have installed.

4. Removing Software:

If you want to remove a package, you can use the apt remove command. For example:

sudo apt remove nano

This removes the Nano text editor from your system.

5. Search for Packages:

To find packages related to a specific keyword, you can use the apt search command:

apt search keyword

Replace keyword with your search term.

Package managers simplify the process of software management, making it efficient and user-friendly. They also handle dependencies automatically, ensuring that all required components are installed correctly. This is one of the strengths of Linux systems, providing a centralized and organized way to manage software installations and updates.

What is a package?

In Linux, a package is a compressed archive that contains software, along with metadata, scripts, and dependencies required for its installation and maintenance. Think of it as a neatly bundled parcel that makes it easy to distribute, install, and manage software on your system. Packages are a fundamental concept in package management systems, which streamline the process of software installation, updates, and removal.

Here are some key points about packages:

  • Comprehensive Content: A package typically includes the actual executable binaries, libraries, configuration files, documentation, and any other necessary files for the software to function properly.

  • Metadata and Dependencies: Packages come with metadata that provides information about the software, such as its version, description, and maintainer. Additionally, packages often list dependencies โ€“ other software components required for the package to run successfully.

  • Consistency and Portability: Packages ensure a consistent and standardized way to distribute software. They encapsulate the software in a format that is easy to transport and install across different systems, maintaining consistency regardless of the underlying environment.

  • Package Formats: Different Linux distributions may use different package formats. For instance:

    • Debian-based systems (e.g., Ubuntu): Use .deb packages managed by tools like apt.

    • Red Hat-based systems (e.g., Fedora, CentOS): Use .rpm packages managed by tools like dnf or yum.

  • Installation and Removal: Package managers handle the installation, upgrade, and removal of packages. This simplifies the user experience by automating tasks and managing dependencies.

  • Example: Let's consider the installation of the htop package, a popular process viewer. On a Debian-based system, you might use:

      sudo apt install htop
    

    This command fetches the htop package and its dependencies, installs them, and ensures the software is ready to use.

Packages are integral to the Linux ecosystem, enabling users to easily access, manage, and maintain a vast array of software applications on their systems. They contribute to the stability, security, and efficiency of software deployment in Linux environments.

Different kinds of package managers?

Certainly! In the Linux world, particularly for Ubuntu, two primary package managers are commonly used: apt and snap. Let's delve into each:

1. APT (Advanced Package Tool):

  • Distribution: Ubuntu and Debian-based systems.

  • Key Commands:

    • Install a package:

        sudo apt install packageName
      
    • Update package lists:

        sudo apt update
      
    • Upgrade installed packages:

        sudo apt upgrade
      
    • Remove a package:

        sudo apt remove packageName
      

APT is known for managing packages in Debian-based systems, providing a robust and easy-to-use way to install, upgrade, and remove software. It handles dependencies efficiently and ensures a smooth software management experience.

2. Snap:

  • Distribution: Ubuntu (and other Linux distributions).

  • Key Commands:

    • Install a Snap package:

        sudo snap install packageName
      
    • Update all Snap packages:

        sudo snap refresh
      
    • Remove a Snap package:

        sudo snap remove packageName
      

Snap is a universal package manager designed for simplicity and portability across different Linux distributions. It includes dependencies within the package, making it a self-contained solution. Snaps can be installed alongside traditional APT packages.

Both APT and Snap offer user-friendly commands, making it convenient for Ubuntu users to install and manage software with ease. Users often choose between them based on their preferences, application availability, and specific use cases.

You have to install docker and jenkins in your system from your terminal using package managers

Let's install Docker and Jenkins on Ubuntu using the apt package manager.

1. Install Docker:

Docker is widely used for containerization. Here's how you can install it:

# Update package lists
sudo apt update

# Install necessary dependencies
sudo apt install apt-transport-https ca-certificates curl software-properties-common

# Add Docker GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

# Add Docker repository
echo "deb [signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

# Update package lists again
sudo apt update

# Install Docker
sudo apt install docker-ce docker-ce-cli containerd.io

# Add your user to the docker group to run Docker commands without sudo
sudo usermod -aG docker $USER

# Log out and log back in or restart your system to apply group changes

Now, Docker is installed on your system.

2. Install Jenkins:

Jenkins is a popular automation server. Let's install it:

# Add the Jenkins GPG key
wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -

# Add Jenkins repository
echo "deb http://pkg.jenkins.io/debian-stable binary/" | sudo tee /etc/apt/sources.list.d/jenkins.list > /dev/null

# Update package lists
sudo apt update

# Install Jenkins
sudo apt install jenkins

# Start Jenkins service
sudo systemctl start jenkins

# Enable Jenkins to start on boot
sudo systemctl enable jenkins

Now, Jenkins is installed and running on your system. You can access Jenkins by opening your web browser and navigating to http://localhost:8080. Follow the on-screen instructions to complete the Jenkins setup.

That's it! You've successfully installed Docker and Jenkins on your Ubuntu system using the apt package manager.

Title: Streamlining Development: Installing Docker and Jenkins on Ubuntu and CentOS

In the dynamic landscape of software development, efficient tools play a pivotal role. Docker for containerization and Jenkins for continuous integration are two such tools that streamline the development process. In this article, we'll guide you through the installation of Docker and Jenkins using package managers on Ubuntu and CentOS.

Installing Docker on Ubuntu:

Step 1: Update Package Lists

sudo apt update

Step 2: Install Dependencies

sudo apt install apt-transport-https ca-certificates curl software-properties-common

Step 3: Add Docker GPG Key

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

Step 4: Add Docker Repository

echo "deb [signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Step 5: Update Package Lists Again

sudo apt update

Step 6: Install Docker

sudo apt install docker-ce docker-ce-cli containerd.io

Step 7: Add User to Docker Group

sudo usermod -aG docker $USER

Step 8: Log Out and Log Back In

Now, Docker is successfully installed on your Ubuntu system.

Installing Jenkins on Ubuntu:

Step 1: Add Jenkins GPG Key

wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -

Step 2: Add Jenkins Repository

echo "deb http://pkg.jenkins.io/debian-stable binary/" | sudo tee /etc/apt/sources.list.d/jenkins.list > /dev/null

Step 3: Update Package Lists

sudo apt update

Step 4: Install Jenkins

sudo apt install jenkins

Step 5: Start Jenkins Service

sudo systemctl start jenkins

Step 6: Enable Jenkins to Start on Boot

sudo systemctl enable jenkins

Now, Jenkins is installed and running on your Ubuntu system. Access it by navigating to http://localhost:8080 in your web browser.

Write a small blog or article to install these tools using package managers on Ubuntu and CentOS

Installing Docker and Jenkins on CentOS:

For Docker: Follow the same steps as outlined for Ubuntu, with slight modifications in package manager commands:

sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install docker-ce docker-ce-cli containerd.io
sudo usermod -aG docker $USER
sudo systemctl start docker

For Jenkins:

sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat/jenkins.io.key
sudo yum install jenkins
sudo systemctl start jenkins
sudo systemctl enable jenkins

Access Jenkins at http://localhost:8080.

By following these steps, you've empowered your development environment with Docker for containerization and Jenkins for automated continuous integration. These tools, easily installable with package managers, contribute to a more efficient and streamlined development workflow.

What are the distinctions between systemctl and service commands for managing services in Linux systems?

systemctl and service are both commands used for controlling services in a Linux system. However, they have some differences in terms of functionality and usage.

systemctl:

  1. Systemd Integration: systemctl is the primary tool for controlling the systemd system and service manager. systemd is a modern system and service manager that has become the standard for many Linux distributions.

  2. More Features: systemctl provides a wide range of functionalities beyond just starting and stopping services. It can manage system state, control the startup process, and handle dependencies.

  3. Standard Syntax:

    • Checking service status: systemctl status serviceName

    • Starting a service: systemctl start serviceName

    • Stopping a service: systemctl stop serviceName

  4. Detailed Output: The systemctl status command provides detailed information about the service, including logs and dependencies.

service:

  1. Traditional System V Init System: service is part of the traditional System V init system, which was the standard init system for many years before systemd became prevalent.

  2. Simpler Commands: service provides a simpler interface compared to systemctl and is often considered more user-friendly for basic service management tasks.

  3. Syntax:

    • Checking service status: service serviceName status

    • Starting a service: service serviceName start

    • Stopping a service: service serviceName stop

  4. Limited Functionality: While service is sufficient for basic service management, it lacks some of the advanced features provided by systemctl.

Examples:

  • Checking Docker Service Status:

    • systemctl status docker: Provides detailed information about the Docker service, including its status, logs, and more.

    • service docker status: Checks the status of the Docker service with simpler output.

  • Starting Docker Service:

    • systemctl start docker: Initiates the Docker service using systemctl.

    • service docker start: Starts the Docker service using the service command.

In summary, while systemctl is more powerful and feature-rich, service is often preferred for its simplicity in basic service management tasks. The choice between them may depend on the init system used by your distribution and personal preferences.

ย