Day 7 Task: Understanding package manager and systemctl
Muhamad Kamran
DevOps Engineer|AWS DevOps Engineer |Linux OS| Git and Github| Docker|Jenkins CI|CD Pipelines | Kubernetes |Python | Azure | Shell Scripting |Ex.NOC & IT Support | CCNA | CCNP | MTCNA | Recommended
What is a package manager in Linux?
In simpler words, a package manager is a tool that allows users to install, remove, upgrade, configure and manage software packages on an operating system. The package manager can be a graphical application like a software center or a command line tool like apt-get or pacman.
You’ll often find me using the term ‘package’ in tutorials and articles, To understand package manager, you must understand what a package is.
What is a package?
A package is usually referred to an application but it could be a GUI application, command line tool or a software library (required by other software programs). A package is essentially an archive file containing the binary executable, configuration file and sometimes information about the dependencies.
Different kinds of package managers
Package Managers differ based on packaging system but same packaging system may have more than one package manager.
Linux:
1. Advanced Package Tool (APT): Used in Debian and Debian-based distributions like Ubuntu.
2. dpkg: Used alongside APT for direct package management on Debian-based systems.
3. YUM (Yellowdog Updater, Modified): Default package manager for Red Hat-based Linux distributions like CentOS and Fedora.
4. DNF (Dandified YUM): The successor to YUM, used in newer Fedora-based distributions.
5. Pacman: Used in Arch Linux and Arch-based distributions.
6. Portage: Used in Gentoo Linux, a source-based package management system.
7. pkg (FreeBSD Package System): Used in FreeBSD and related BSD operating systems.
Tasks
1. You have to install docker and jenkins in your system from your terminal using package managers
2. Write a small blog or article to install these tools using package managers on Ubuntu and CentOS
o install Docker and Jenkins on your system using package managers, the specific package manager and installation commands may vary depending on your operating system. Below are instructions for installing Docker and Jenkins on Ubuntu using APT:
Installing Docker on Ubuntu:
Update the package list and install required dependencies:
sudo apt update
sudo apt install apt-transport-https ca-certificates curl software-properties-common
Add Docker's official GPG key to ensure the authenticity of the Docker packages:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
Add the Docker repository to your system:
For x86_64 (64-bit):
echo "deb [arch=amd64 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
For arm64 (64-bit ARM):
echo "deb [arch=arm64 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 the package list and install Docke
sudo apt update
sudo apt install docker-ce
Start and enable Docker to run at boot:
sudo systemctl start docker
sudo systemctl enable docker
Verify that Docker is installed and running:
sudo docker –version
Installing Jenkins on Ubuntu:
Import the GPG key for the Jenkins repository:
wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add –
Add the Jenkins repository to your system:
sudo sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
Update the package list and install Jenkins:
sudo apt update
sudo apt install jenkins
Start and enable Jenkins to run at boot:
sudo systemctl start jenkins
sudo systemctl enable jenkins
Open a web browser and access Jenkins at https://localhost:8080 or the IP address of your server on port 8080. You will need to retrieve the initial admin password from your system:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Installing Docker and Jenkins on Ubuntu Using Package Managers
领英推荐
Ubuntu, one of the most popular Linux distributions, provides a straightforward way to install software packages using package managers. In this article, we'll guide you through the installation of two powerful tools, Docker and Jenkins, using package managers on an Ubuntu system.
Installing Docker on Ubuntu
Docker is a containerization platform that simplifies application deployment by packaging applications and their dependencies into containers. Here's how you can install Docker on your Ubuntu system using the APT package manager:
1. Update the Package List and Install Dependencies: Open your terminal and run the following commands to update the package list and install necessary dependencies.
sudo apt update sudo apt install apt-transport-https ca-certificates curl software-properties-common
2. Add Docker's Official GPG Key: To ensure the authenticity of Docker packages, add Docker's GPG key to your system.
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
3. Add the Docker Repository: Depending on your system architecture (x86_64 or arm64), add the appropriate Docker repository.
For x86_64 (64-bit):
echo "deb [arch=amd64 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
For arm64 (64-bit ARM):
echo "deb [arch=arm64 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
4. Install Docker: Update the package list again and install Docker.
sudo apt update sudo apt install docker-ce
5. Start and Enable Docker: Start Docker and enable it to run at system boot.
sudo systemctl start docker sudo systemctl enable docker
6. Verify Docker Installation: Check if Docker is successfully installed.
sudo docker --version
Docker is now up and running on your Ubuntu system, allowing you to create, manage, and run containers effortlessly.
Installing Jenkins on Ubuntu
Jenkins is a powerful automation server that enables continuous integration and continuous delivery (CI/CD) workflows. Let's go through the process of installing Jenkins using APT:
1. Import Jenkins GPG Key: Import the GPG key for the Jenkins repository using the following command.
wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
2. Add Jenkins Repository: Add the Jenkins repository to your system.
sudo sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
3. Update the Package List and Install Jenkins: Update the package list and install Jenkins.
sudo apt update sudo apt install jenkins
4. Start and Enable Jenkins: Start Jenkins and enable it to run at system boot.
sudo systemctl start jenkins sudo systemctl enable jenkins
5. Access Jenkins Web Interface: Open a web browser and access Jenkins at https://localhost:8080. Retrieve the initial admin password from your system with this command:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Follow the on-screen instructions to complete the Jenkins setup.
You now have Jenkins installed on your Ubuntu system, allowing you to automate build, test, and deployment processes efficiently.
By following these step-by-step instructions, you can quickly set up Docker and Jenkins on your Ubuntu machine using package managers. These tools are essential for modern software development and deployment, and they will greatly enhance your development workflow.
systemctl and systemd
systemctl is used to examine and control the state of “systemd” system and service manager. systemd is system and service manager for Unix like operating systems(most of the distributions, not all).
1. check the status of docker service in your system
sudo systemctl status docker
2. read about the commands systemctl vs service
eg. systemctl status docker vs service docker status
In Linux, there are two commonly used commands to check the status of a service: systemctl and service. Here's how you can use both commands to check the status of the Docker service:
Using systemctl:
To check the status of the Docker service using systemctl, run the following command:
sudo systemctl status docker
This command will provide detailed information about the Docker service, including whether it's active, its process ID (PID), and recent logs.
1. Using service:
To check the status of the Docker service using the service command, run the following:
sudo service docker status
The service command provides a more concise status report, typically showing whether the service is running or not.
While both commands can be used to check service status, systemctl is more feature-rich and is the recommended way to interact with services on modern Linux systems. It provides more detailed information and offers additional functionality for managing services. The service command is a legacy method, and its use may vary between different Linux distributions.