Day 7 : Understanding package manager and systemctl
I am Yashraj Singh Sisodiya, a 3rd Year CSE student at SVVV, born and raised in Shujalpur. Currently residing in Indore, I'm passionate about pursuing a career in DevOps engineering. My tech journey began with an internship at Infobyte, honing my skills as an Android Developer intern. Alongside my academic pursuits, I actively participate in co-curriculars, holding roles as Technical Lead at Abhyudaya and Cloud Lead at GDSC SVVV, while also serving as an MLSA of my college.
I have a keen interest in Cloud Computing, demonstrated through projects such as User management and Backup using shell scripting Linux, Dockerizing applications, CI/CD with Jenkins, and deploying a 3-tier application on AWS. Always eager to learn, I'm committed to expanding my knowledge and skills in the ever-evolving tech landscape.
Introduction:
A package manager in Linux streamlines software installation, ensuring efficient management. systemctl controls system services, simplifying their administration. Both are pivotal tools for effective Linux system maintenance.
What is a package manager in Linux?
In Linux, a package manager is a tool that helps you install, update, and manage software packages on your system. Think of it as a convenient way to handle the installation and maintenance of software, saving you from the hassle of manual downloads, dependencies, and configurations.
One of the most widely used package managers is apt for Debian-based distributions (like Ubuntu). Let me break down some common tasks using apt:
1. Installing Software:
To install a package, you simply use the apt install command. For example, let's install a text editor called nano:
sudo apt install nano
This command fetches the latest version of Nano and installs it on your system.
2. Updating Package Lists:
Before installing or upgrading software, it's good to update the package lists to get the latest information about available packages. Run:
sudo apt update
This command fetches the latest package information from the repositories.
3. Upgrading Installed Packages:
To upgrade your installed packages to the latest versions, use:
sudo apt upgrade
This command installs the latest versions of packages you have installed.
4. Removing Software:
If you want to remove a package, you can use the apt remove command. For example:
sudo apt remove nano
This removes the Nano text editor from your system.
5. Search for Packages:
To find packages related to a specific keyword, you can use the apt search command:
apt search keyword
Replace keyword with your search term.
Package managers simplify the process of software management, making it efficient and user-friendly. They also handle dependencies automatically, ensuring that all required components are installed correctly. This is one of the strengths of Linux systems, providing a centralized and organized way to manage software installations and updates.
What is a package?
In Linux, a package is a compressed archive that contains software, along with metadata, scripts, and dependencies required for its installation and maintenance. Think of it as a neatly bundled parcel that makes it easy to distribute, install, and manage software on your system. Packages are a fundamental concept in package management systems, which streamline the process of software installation, updates, and removal.
Here are some key points about packages:
Comprehensive Content: A package typically includes the actual executable binaries, libraries, configuration files, documentation, and any other necessary files for the software to function properly.
Metadata and Dependencies: Packages come with metadata that provides information about the software, such as its version, description, and maintainer. Additionally, packages often list dependencies β other software components required for the package to run successfully.
Consistency and Portability: Packages ensure a consistent and standardized way to distribute software. They encapsulate the software in a format that is easy to transport and install across different systems, maintaining consistency regardless of the underlying environment.
Package Formats: Different Linux distributions may use different package formats. For instance:
Debian-based systems (e.g., Ubuntu): Use
.debpackages managed by tools likeapt.Red Hat-based systems (e.g., Fedora, CentOS): Use
.rpmpackages managed by tools likednforyum.
Installation and Removal: Package managers handle the installation, upgrade, and removal of packages. This simplifies the user experience by automating tasks and managing dependencies.
Example: Let's consider the installation of the
htoppackage, a popular process viewer. On a Debian-based system, you might use:sudo apt install htopThis command fetches the
htoppackage and its dependencies, installs them, and ensures the software is ready to use.
Packages are integral to the Linux ecosystem, enabling users to easily access, manage, and maintain a vast array of software applications on their systems. They contribute to the stability, security, and efficiency of software deployment in Linux environments.
Different kinds of package managers?
Certainly! In the Linux world, particularly for Ubuntu, two primary package managers are commonly used: apt and snap. Let's delve into each:
1. APT (Advanced Package Tool):
Distribution: Ubuntu and Debian-based systems.
Key Commands:
Install a package:
sudo apt install packageNameUpdate package lists:
sudo apt updateUpgrade installed packages:
sudo apt upgradeRemove a package:
sudo apt remove packageName
APT is known for managing packages in Debian-based systems, providing a robust and easy-to-use way to install, upgrade, and remove software. It handles dependencies efficiently and ensures a smooth software management experience.
2. Snap:
Distribution: Ubuntu (and other Linux distributions).
Key Commands:
Install a Snap package:
sudo snap install packageNameUpdate all Snap packages:
sudo snap refreshRemove a Snap package:
sudo snap remove packageName
Snap is a universal package manager designed for simplicity and portability across different Linux distributions. It includes dependencies within the package, making it a self-contained solution. Snaps can be installed alongside traditional APT packages.
Both APT and Snap offer user-friendly commands, making it convenient for Ubuntu users to install and manage software with ease. Users often choose between them based on their preferences, application availability, and specific use cases.
You have to install docker and jenkins in your system from your terminal using package managers
Let's install Docker and Jenkins on Ubuntu using the apt package manager.
1. Install Docker:
Docker is widely used for containerization. Here's how you can install it:
# Update package lists
sudo apt update
# Install necessary dependencies
sudo apt install apt-transport-https ca-certificates curl software-properties-common
# Add Docker GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
# Add Docker repository
echo "deb [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 package lists again
sudo apt update
# Install Docker
sudo apt install docker-ce docker-ce-cli containerd.io
# Add your user to the docker group to run Docker commands without sudo
sudo usermod -aG docker $USER
# Log out and log back in or restart your system to apply group changes
Now, Docker is installed on your system.
2. Install Jenkins:
Jenkins is a popular automation server. Let's install it:
# Add the Jenkins GPG key
wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
# Add Jenkins repository
echo "deb http://pkg.jenkins.io/debian-stable binary/" | sudo tee /etc/apt/sources.list.d/jenkins.list > /dev/null
# Update package lists
sudo apt update
# Install Jenkins
sudo apt install jenkins
# Start Jenkins service
sudo systemctl start jenkins
# Enable Jenkins to start on boot
sudo systemctl enable jenkins
Now, Jenkins is installed and running on your system. You can access Jenkins by opening your web browser and navigating to http://localhost:8080. Follow the on-screen instructions to complete the Jenkins setup.
That's it! You've successfully installed Docker and Jenkins on your Ubuntu system using the apt package manager.
Title: Streamlining Development: Installing Docker and Jenkins on Ubuntu and CentOS
In the dynamic landscape of software development, efficient tools play a pivotal role. Docker for containerization and Jenkins for continuous integration are two such tools that streamline the development process. In this article, we'll guide you through the installation of Docker and Jenkins using package managers on Ubuntu and CentOS.
Installing Docker on Ubuntu:
Step 1: Update Package Lists
sudo apt update
Step 2: Install Dependencies
sudo apt install apt-transport-https ca-certificates curl software-properties-common
Step 3: Add Docker GPG Key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
Step 4: Add Docker Repository
echo "deb [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
Step 5: Update Package Lists Again
sudo apt update
Step 6: Install Docker
sudo apt install docker-ce docker-ce-cli containerd.io
Step 7: Add User to Docker Group
sudo usermod -aG docker $USER
Step 8: Log Out and Log Back In
Now, Docker is successfully installed on your Ubuntu system.
Installing Jenkins on Ubuntu:
Step 1: Add Jenkins GPG Key
wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
Step 2: Add Jenkins Repository
echo "deb http://pkg.jenkins.io/debian-stable binary/" | sudo tee /etc/apt/sources.list.d/jenkins.list > /dev/null
Step 3: Update Package Lists
sudo apt update
Step 4: Install Jenkins
sudo apt install jenkins
Step 5: Start Jenkins Service
sudo systemctl start jenkins
Step 6: Enable Jenkins to Start on Boot
sudo systemctl enable jenkins
Now, Jenkins is installed and running on your Ubuntu system. Access it by navigating to http://localhost:8080 in your web browser.
Write a small blog or article to install these tools using package managers on Ubuntu and CentOS
Installing Docker and Jenkins on CentOS:
For Docker: Follow the same steps as outlined for Ubuntu, with slight modifications in package manager commands:
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install docker-ce docker-ce-cli containerd.io
sudo usermod -aG docker $USER
sudo systemctl start docker
For Jenkins:
sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat/jenkins.io.key
sudo yum install jenkins
sudo systemctl start jenkins
sudo systemctl enable jenkins
Access Jenkins at http://localhost:8080.
By following these steps, you've empowered your development environment with Docker for containerization and Jenkins for automated continuous integration. These tools, easily installable with package managers, contribute to a more efficient and streamlined development workflow.
What are the distinctions between systemctl and service commands for managing services in Linux systems?
systemctl and service are both commands used for controlling services in a Linux system. However, they have some differences in terms of functionality and usage.
systemctl:
Systemd Integration:
systemctlis the primary tool for controlling thesystemdsystem and service manager.systemdis a modern system and service manager that has become the standard for many Linux distributions.More Features:
systemctlprovides a wide range of functionalities beyond just starting and stopping services. It can manage system state, control the startup process, and handle dependencies.Standard Syntax:
Checking service status:
systemctl status serviceNameStarting a service:
systemctl start serviceNameStopping a service:
systemctl stop serviceName
Detailed Output: The
systemctl statuscommand provides detailed information about the service, including logs and dependencies.
service:
Traditional System V Init System:
serviceis part of the traditional System V init system, which was the standard init system for many years beforesystemdbecame prevalent.Simpler Commands:
serviceprovides a simpler interface compared tosystemctland is often considered more user-friendly for basic service management tasks.Syntax:
Checking service status:
service serviceName statusStarting a service:
service serviceName startStopping a service:
service serviceName stop
Limited Functionality: While
serviceis sufficient for basic service management, it lacks some of the advanced features provided bysystemctl.
Examples:
Checking Docker Service Status:
systemctl status docker: Provides detailed information about the Docker service, including its status, logs, and more.service docker status: Checks the status of the Docker service with simpler output.
Starting Docker Service:
systemctl start docker: Initiates the Docker service usingsystemctl.service docker start: Starts the Docker service using theservicecommand.
In summary, while systemctl is more powerful and feature-rich, service is often preferred for its simplicity in basic service management tasks. The choice between them may depend on the init system used by your distribution and personal preferences.




