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, YUM or pacman.
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.
Task 1: You have to install docker and Jenkins in your system from your terminal using package managers
Commands used to install Docker and Manage Docker :
- Remove any Docker files that are running in the system, using the following command:
$ sudo apt-get remove docker docker-engine docker.io
2. Check if the system is up-to-date using the following command:
$ sudo apt-get update
3. Install Docker using the following command:
$ sudo apt install docker.io
4. Install all the dependency packages using the following command:
$ sudo snap install docker
5. Before testing Docker, check the version installed using the following command:
$ docker --version
6 . Pull an image from the Docker hub using the following command:
$ sudo docker run hello-world
Here, hello-world is the docker image present on the Docker hub.
7. Check if the docker image has been pulled and is present in your system using the following command:
$ sudo docker images
8. To display all the containers pulled, use the following command:
$ sudo docker ps -a
9. To check for containers in a running state, use the following command:
$ sudo docker ps
You’ve just successfully installed Docker on Ubuntu!
Install Jenkins:-
Check the below website for step-by-step installation of Jenkins on your Ubuntu server.
How To Install Jenkins on Ubuntu 22.04 | DigitalOcean
Jenkins is an open-source automation server that automates the repetitive technical tasks involved in the continuous…
What is systemctl and systemd ?
systemd
is a Linux init system and system manager that is widely used in modern Linux distributions as the default init system. It provides a way to manage and control the various services that run on a Linux system, as well as other system-level functionality.
systemctl
is the command line tool used to control and manage the systemd
system and service manager. It provides various commands to start, stop, restart, enable, and disable services, as well as other functionalities such as inspecting the status of services, displaying log messages, and managing system-level settings and configurations.
Here are a few examples of common tasks that can be performed using systemctl
:
Start a service:
systemctl start <service-name>
Stop a service:
systemctl stop <service-name>
Restart a service:
systemctl restart <service-name>
Enable a service to start automatically at boot:
systemctl enable <service-name>
Disable a service from starting automatically at boot:
systemctl disable <service-name>
Check the status of a service:
systemctl status <service-name>
Overall, systemd
and systemctl
provide a centralized and standardized way to manage services and other system-level components on Linux, making it easier to configure and maintain a Linux system.
- check the status of docker service in your system (make sure you completed above tasks, else docker won’t be installed)
2. stop the service Jenkins and post before and after screenshots
Before :
After:
#systemctl stop jenkins
#systemctl status jenkins
3. Read about the commands systemctl vs service
systemctl
and service
are both tools used to manage and control services on a Linux system. However, they have some differences:
systemctl
is the newer tool and is used on systems that use the Systemd init system, which is now widely adopted as the default init system for many popular Linux distributions, including Fedora, Red Hat Enterprise Linux, and Ubuntu.service
is the older tool and is used on systems that use the System V init system, which was the previous standard init system used in many popular Linux distributions.systemctl
provides more advanced features compared toservice
, such as the ability to manage units, which are the basic building blocks of Systemd. This allows you to manage not just services, but also other system components, such as sockets, devices, and mount points, with a unified interface.service
is limited to managing services only, and its syntax and options are not as advanced as those ofsystemctl
.Package Manager Commands:
APT (Debian/Ubuntu):
sudo apt update
: Updates the local package repository.sudo apt upgrade
: Upgrades installed packages to their latest versions.sudo apt install package_name
: Installs a specific package.sudo apt remove package_name
: Removes a specific package.sudo apt search package_name
: Searches for a package in the repository.sudo apt autoremove
: Removes unused packages and their dependencies.
DNF (Fedora/RHEL):
sudo dnf update
: Updates the local package repository.sudo dnf upgrade
: Upgrades installed packages to their latest versions.sudo dnf install package_name
: Installs a specific package.sudo dnf remove package_name
: Removes a specific package.sudo dnf search package_name
: Searches for a package in the repository.sudo dnf autoremove
: Removes unused packages and their dependencies.
Pacman (Arch Linux):
sudo pacman -Syu
: Updates the local package repository and upgrades all packages.sudo pacman -S package_name
: Installs a specific package.sudo pacman -R package_name
: Removes a specific package.sudo pacman -Ss package_name
: Searches for a package in the repository.sudo pacman -Sc
: Deletes the old versions of installed packages.
Systemctl Commands:
Managing Services:
sudo systemctl start service_name
: Starts a service.sudo systemctl stop service_name
: Stops a service.sudo systemctl restart service_name
: Restarts a service.sudo systemctl enable service_name
: Enables a service to start at boot.sudo systemctl disable service_name
: Disables a service from starting at boot.
Checking Service Status:
sudo systemctl status service_name
: Shows the status and information of a service.sudo systemctl is-active service_name
: Checks if a service is active.sudo systemctl is-enabled service_name
: Checks if a service is enabled.sudo systemctl is-failed service_name
: Checks if a service has failed.
Package Manager Tips:
Updating Package Lists:
- Before installing or upgrading packages, it's a good practice to update the package lists first. Use the command
sudo apt update
(for APT) orsudo dnf update
(for DNF) to ensure you have the latest information about available packages.
- Before installing or upgrading packages, it's a good practice to update the package lists first. Use the command
Package Repository Management:
- You can manage software sources and repositories by editing the appropriate configuration files. For example, in Ubuntu, you can modify the repository sources in the
/etc/apt/sources.list
file or add new sources in/etc/apt/sources.list.d/
directory.
- You can manage software sources and repositories by editing the appropriate configuration files. For example, in Ubuntu, you can modify the repository sources in the
Package Version Locking:
- Sometimes, you may want to prevent a package from being upgraded to a newer version. Package managers offer a version locking feature for this purpose. For example, in APT, you can use the
sudo apt-mark hold package_name
command to prevent a package from being upgraded.
- Sometimes, you may want to prevent a package from being upgraded to a newer version. Package managers offer a version locking feature for this purpose. For example, in APT, you can use the
Systemctl Tips:
Checking Service Logs:
- You can view the logs generated by a service using the
journalctl
command. For example, to view the logs of the Apache web server, you can usesudo journalctl -u apache2
.
- You can view the logs generated by a service using the
Service Dependency Management:
- Services can have dependencies on other services. You can specify service dependencies in the unit files located in
/etc/systemd/system/
. Use theRequires
andAfter
directives to define dependencies between services.
- Services can have dependencies on other services. You can specify service dependencies in the unit files located in
Service Configuration Reloading:
- After making changes to a service's configuration file, you can reload the configuration without restarting the service. Use the command
sudo systemctl reload service_name
to apply the changes.
- After making changes to a service's configuration file, you can reload the configuration without restarting the service. Use the command
Example Usage:
Installing a package:
Suppose you want to install the
nginx
web server using APT. You can run the following commands:sudo apt update sudo apt install nginx
This will update the package lists and then install the
nginx
package along with its dependencies.
Enabling and starting a service:
Let's say you want to enable and start the
apache2
service using systemctl. You can use the following commands:sudo systemctl enable apache2 sudo systemctl start apache2
This will enable the
apache2
service to start at boot and then start the service immediately.
Checking the status of a service:
To check the status of the
sshd
service, you can use the command:sudo systemctl status sshd
This will display information about the current status, whether the service is active, and any recent logs related to the service.
These tips and examples should help you get started with package managers and systemctl in Linux. Remember to adjust the commands based on your specific Linux distribution and package manager.