Understanding package manager and systemctl
🔹What is a package manager in Linux?
In the Linux world, a package manager is a crucial tool that simplifies software installation, removal, upgrading, configuration, and management on the operating system. It ensures that software packages are easily accessible, maintained, and compatible with the system. Package managers are available as both graphical applications, such as software centers, and command-line tools like apt-get or pacman.
🔹What is a package?
Before delving into package managers, it's essential to comprehend what a package is. In the context of Linux, a package typically refers to an application. However, it can also be a GUI application, a command-line tool, or a software library required by other programs. A package is essentially an archive file containing the binary executable, configuration files, and sometimes information about its dependencies.
🔹Different kinds of package managers
Package managers can vary based on the packaging system, and a single packaging system may have multiple package managers. For example:
RPM (Red Hat Package Manager) has Yum and DNF package managers.
DEB packages use apt-get and aptitude as command-line-based package managers.
1. Docker Installation:
On Ubuntu (using apt):Update the apt
package index and install packages to allow apt
to use a repository over HTTPS:
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
Add Docker’s official GPG key:
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
Use the following command to set up the repository:
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Update the apt
package index:
sudo apt-get update
Install Docker Engine, containerd, and Docker Compose.
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Verify that the Docker Engine installation is successful by running the hello-world
image.
sudo systemctl enable docker
sudo systemctl status docker
sudo docker run hello-world
Jenkins Installation:
On Ubuntu (using apt):
sudo apt update
sudo apt install openjdk-11-jre
#Install Jenkins
curl -fsSL https://pkg.jenkins.io/debian/jenkins.io.key | sudo tee \ /usr/share/keyrings/jenkins-keyring.asc > /dev/null
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \ https://pkg.jenkins.io/debian binary/ | sudo tee \ /etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update
sudo apt-get install jenkins
#Start jenkins
sudo systemctl enable jenkins
sudo systemctl start jenkins
sudo systemctl status jenkins
To stop the Jenkins service and capture before and after screenshots, use the following commands:
sudo systemctl stop jenkins
systemctl and systemd:
systemctl
and service
are both commands used to manage services in Linux, but they operate differently and are associated with different system management frameworks.
systemctl:
systemctl
is a command-line tool used to control the systemd system and service manager. systemd is a modern init system and service manager that has become the default for many Linux distributions. It is responsible for managing the boot process, starting and stopping services, and handling system processes.
Key features of systemctl
include:
Unit Management: systemd treats all managed components, such as services, devices, and sockets, as units.
systemctl
allows you to manage these units.Status Information: You can use
systemctl
to view the status of a service, check if it is active or inactive, and see any errors or warnings related to it.Service Control:
systemctl
provides commands to start, stop, restart, enable, disable, and reload services.
Example commands with systemctl
:
systemctl status docker
service:
service
is a legacy command used to interact with the init system. The init system is the traditional system initialization mechanism used in older Linux distributions. It predates systemd and is still used in some systems.
Key features of service
include:
Init System Interaction: The
service
command is designed to manage services using the older init system scripts located in the/etc/init.d/
directory.Service Control: It provides a simple and standardized way to start, stop, and restart services.
Example commands with service
:
service docker status
Which one to use?
It is generally recommended to use systemctl
whenever possible, especially on newer Linux distributions that use systemd as the default init system. systemd is more powerful and offers more features for managing services. Additionally, many older init scripts have been adapted to work with systemd and can be managed using systemctl
.
However, service
can still be used on older systems or in situations where systemd is not available or not used as the init system.
In conclusion, systemctl
and service
are both used for managing services in Linux, but systemctl
is the more modern and powerful option, while service
is a legacy command that may still be useful on older systems.