Day 7 Task: Understanding package manager and systemctl
What is a package manager in Linux?
In simpler words, a package manager is a tool that automates the process of installing, removing, 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.
Key Functions of a Package Manager:
Installation: Install new software packages with a single command.
Removal: Uninstall software you no longer need without leaving behind any clutter.
Upgrade: Keep your software up to date effortlessly.
Configuration: Handle initial setup and ongoing configuration of software.
Dependency Management: Automatically manage and resolve software dependencies.
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.
For example, RPM has Yum and DNF package managers. For DEB, you have apt-get, aptitude command line based package managers.
apt-get: A command-line tool used in Debian-based distributions like Ubuntu. It's powerful and widely used.
YUM (Yellowdog Updater Modified) and DNF (Dandified YUM): Used in Red Hat-based systems like Fedora and CentOS.
zypper: The command-line interface for zypper package management engine, used in openSUSE and SUSE Linux Enterprise. It's robust and versatile.
Pacman: Used in Arch Linux.
Workflow of a Package Manager:
Update Package List: The package manager fetches the latest list of available packages from the repositories.
Install Package: You issue a command to install a package. The package manager checks for dependencies and downloads the necessary files.
Resolve Dependencies: The package manager ensures all dependencies are met, downloading and installing any additional packages required.
Configure Software: During installation, you might be prompted to configure certain aspects of the software.
Complete Installation: The package is installed and ready to use.
Task1: Install Docker and Jenkins:
- Install Docker and Jenkins on your system from your terminal using package managers.
sudo apt update
sudo apt install docker.io
Jenkins requires Java to run. You can install OpenJDK (an open-source implementation of Java) with the following command.
sudo apt update
sudo apt install openjdk-17-jre
- Jenkins Installation
curl -fsSL https://pkg.jenkins.io/debian/jenkins.io-2023.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 the Jenkins service and enable it to start on boot.
sudo systemctl start jenkins
sudo systemctl enable jenkins
Jenkins runs on port 8080 by default. Open your web browser and navigate to
http://your_server_ip_or_domain:8080
Task2: Check Docker Service Status:
- Check the status of the Docker service on your system (ensure you have completed the installation tasks above).
sudo systemctl status docker
Task3: Manage Jenkins Service:
sudo systemctl status jenkins
Managing System Services with systemctl and Service
systemctl
is a command-line tool used to manage system services in Linux. It works with systemd, the system and service manager.
service
is a command used to interact with the init system. The service
command provides a way to start, stop, and check the status of system services, and it abstracts the underlying init system to provide a consistent interface
Here, are some key commands:
Start a service:
sudo systemctl start service_name
Stop a service:
sudo systemctl stop service_name
Check the status of a service:
sudo systemctl status service_name
Restart a service:
sudo systemctl restart service_name
Enable a service at boot:
sudo systemctl enable service_name
Disable a service:
sudo systemctl disable service_name
Using systemctl
:
sudo systemctl start docker
Using service
:
sudo service docker start
Stopping a Service
- Using
systemctl
:
systemctl stop docker
Using service
:
sudo service docker stop
Enabling a Service to Start on Boot
- Using
systemctl
:
systemctl enable docker
- Using
service
: Note: Theservice
command itself does not handle enabling services at boot. This is typically managed by updating runlevel symlinks directly or usingchkconfig
orupdate-rc.d
.