Linux Package Manager
🚀A package manager is a tool that allows users to install, remove, upgrade, configure and manage software packages on an operating system.
Packages include metadata like the name of the software, description of its objective, checksum (a cryptographic hash function preferably), dependency list, vendor, and version number essential for the software to properly run.
The package manager can be a graphical application like a software center or a command line tool like apt-get or pacman.
Pic credit: Javatpoint
🚀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 the packaging system but same packaging system may have more than one package manager.
For example, RPM has Yum and DNF package managers. For DEB, you have apt-get, aptitude command line-based package managers.
sudo yum update -y command in Linux is used on Red Hat-based distributions such as CentOS and Fedora to update the installed packages to the latest available versions. Here's what each part of the command does:
sudo: Executes the command with superuser (root) privileges, allowing you to make system-wide changes.
yum: The package management tool used in Red Hat-based Linux distributions for installing, updating, and removing packages.
update: This sub-command instructs yum to update all installed packages to their latest versions.
-y: Automatically confirms any prompts that ask for confirmation to install or update packages. It is used to skip the need for manual confirmation during the update process.
Let's have a quick demo of Package Installation for Docker:
Docker is a platform for running applications in an isolated environment called a "container" (or Docker container). Applications like Jenkins can be downloaded as read-only "images" (or Docker images), each of which is run in Docker as a container. A Docker container is a "running instance" of a Docker image. A Docker image is stored permanently, based on when image updates are published, whereas containers are stored temporarily.
To install docker, I will use the Amazon EC2 Linux instance. With the help of official docker documentation, we can easily follow the installation procedure here:
Step 1: sudo yum -y install docker
Step 2: sudo systemctl start docker
Access Docker commands in ec2-user user
Step 3: sudo usermod -a -G docker ec2-user
Step 4: docker version
docker –version
For installing docker on CentOS, please follow this documentation
Lets understand what is Jenkins and how we can install with the help of Package Manager:
Jenkins :
Jenkins is an open-source automation server. It helps automate the parts of software development related to building, testing, and deploying, facilitating continuous integration and continuous delivery. It is a server-based system that runs in servlet containers such as Apache Tomcat.
It can be used to build software, deploy software, or websites to various endpoints or to run unit/behaviour-driven software tests.
By this article you can learn step by step that how to install, configure Jenkins, and how to create your first job. After setting up the basics, you’ll schedule the build on specific times and install a plugin.
So, let’s start the setup of Jenkins on Amazon EC2 Linux operating system. With the help of official Jenkins documentation, we can easily follow the installation procedure here:
- Add the Jenkins repo using the following command:
sudo wget -O /etc/yum.repos.d/jenkins.repo \
https://pkg.jenkins.io/redhat-stable/jenkins.repo
Import a key file from Jenkins-CI to enable installation from the package:
sudo rpm --import
https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
sudo yum upgrade
- Install Java (Amazon Linux 2023):
sudo dnf install java-17-amazon-corretto -y
Install Jenkins:
sudo yum install jenkins -y
- Enable the Jenkins service to start at boot:
sudo systemctl enable jenkins
Start Jenkins as a service:
sudo systemctl start jenkins
- You can check the status of the Jenkins service using the command:
sudo systemctl status jenkins
Configuring Jenkins
Jenkins is now installed and running on your EC2 instance. To configure Jenkins:
You need to open the port 8080 to enable traffic from jenkins
- Connect to http://<your_server_public_DNS>:8080 from your browser. You will be able to access Jenkins through its management interface:
http://ec2-34-216-157-206.us-west-2.compute.amazonaws.com:8080/
As prompted, enter the password found in /var/lib/jenkins/secrets/initialAdminPassword.
Use the following command to display this password:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
The Jenkins installation script directs you to the Customize Jenkins page. Click Install suggested plugins.
Once the installation is complete, the Create First Admin User will open. Enter your information, and then select Save and Continue.
On the left-hand side, select Manage Jenkins, and then select Manage Plugins.
Select the Available tab, and then enter Amazon EC2 plugin at the top right.
Select the checkbox next to the Amazon EC2 plugin, and then select Install without restart.
Once the installation is done, select Back to Dashboard.
This is how Jenkins is installed on a Linux EC2 instance
What is systemctl and systemd ?
systemctl is the systemd command for controlling how services start on a Linux system. A service can be enabled, disabled, or masked, and it can be configured to start at boot, on demand, manually, or prevented from starting under any circumstances. Systemd and systemctl work together to provide more efficient and flexible system management for Linux. systemd is designed to improve system boot and shutdown times, provide better resource management, and offer more detailed logging and debugging capabilities.
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).
Enabling and disabling services with systemctl
Enabling a service means it will start at boot. Disabling a service means it will not start at boot, but can be started manually, or as a dependency of another service. Enabling or disabling a running service does not automatically change its current state; if it is running, it will continue to run, and if it is not running, it will not start. When you enable or disable a service, you have the option to stop or start the service with a separate command or to enable/disable and start/stop with a single command.
A masked service cannot be started by any means and must be unmasked to be usable.
systemctl is-enabled SERVICE-NAME
Check if a service is enabled or disabled.
systemctl status SERVICE-NAME
Check if a service is running, stopped, enabled, or masked, and display the most recent log entries.
systemctl enable SERVICE-NAME
Enable a service, without starting it. It will start automatically at the next system restart, or it can be started manually, or as a dependency of another service.
eg. systemctl status docker vs service docker status
systemctl status docker
The systemctl status docker
command is used to check the status of the Docker service on a Linux system that uses systemd
as its init system and service manager. When you run this command, it provides detailed information about the current state of the Docker service, including whether it is running or stopped, any recent log messages, and more.
service docker status
The service docker status
command is used to check the status of the Docker service on Linux systems using traditional init scripts. This command queries the system's init system to determine whether the Docker service is running, stopped, or in any other state.
Subscribe to my newsletter
Read articles from Asma Akram directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by