# Understanding package manager and systemctl..

### *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 lines tool like apt-get.*

*You’ll often find me using the term ‘package’ in tutorials and articles, To understand package manager, you must understand what a package is.*

### *What is a package?*

*A package is usually referred to as 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 the 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.*

### ***Install Docker using the package manager***

*Check if the system is up-to-date*

```bash
sudo apt-get update  
```

*Install Docker*

```bash
sudo apt-get install docker.io -y
```

*Check the installed version of the docker*

```bash
docker --version
```

### ***Install Jenkins using the package manager***

*Jenkins requires the Java Runtime Environment (JRE)*

*Install java*

```bash
sudo apt update
sudo apt install openjdk-17-jre
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690306716535/d0651430-ad72-493d-8727-a3e83ec1e9f9.png align="center")

*Check the installed version of the java*

```bash
java --version
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690306639129/766ec489-5f29-4b71-9e8e-6419b384b222.png align="center")

*Add the Jenkins repository*

```bash
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
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690307052814/e5832831-fcc3-4cea-b803-633b01df0798.png align="center")

*Update Package manager*

```bash
sudo apt-get update
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690307093668/5b8b3380-3f03-4825-b6e9-900e566a3168.png align="center")

*Install Jenkins*

```bash
sudo apt-get install jenkins
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690307291097/086c0fa4-8aa2-4df4-853c-23f2a9efcaea.png align="center")

*To check the version of Jenkins*

```bash
jenkins --version
```

### ***systemctl and systemd***

*systemctl is used to examine and control the state of the “systemd” system and service manager. systemd is a system and service manager for Unix-like operating systems(most of the distributions, not all).*

### ***Check the status of the docker service in your system***

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690307673062/7809f35b-9970-4c17-accb-2709d1897025.png align="center")

```bash
systemctl status docker
```

### ***Stop the service, Jenkins***

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1690308066646/012833bc-b715-4dac-a97d-d45342d9c1ae.png align="center")

```bash
sudo systemctl stop jenkins
```

### ***systemctl vs service***

`systemctl` *and* `service` *are both commands used in Linux-based operating systems to manage services, but they differ in their functionality and the systems they are associated with.* `systemctl` *is a more modern and powerful command used in systems that use* `systemd` *as their init system.*

*With* `systemctl`*, you can start, stop, restart, enable, disable, and check the status of services.*

```bash
sudo systemctl status jenkins #Status of a service
sudo systemctl start jenkins  #Start a service
sudo systemctl stop jenkins   #Stop a service
sudo systemctl restart jenkins #retart a service
sudo systemctl enable jenkins  #enable a service
sudo systemctl disable jenkins  #disbale a service
```

`service` *is a legacy command that was commonly used in systems with the SysVinit init system, which was prevalent before the adoption of* `systemd`*. While many modern distributions have switched to* `systemd`*, some older systems or specific setups might still use SysVinit or its variants.*

`service` *provides a simple interface to start, stop, and restart services, but it does not handle more advanced features like dependencies or system target states, as offered by* `Systemctl`*.*

*Examples of using* `service`*:*

```bash
sudo service docker start  #Start a service
sudo service docker stop    #Stop a service
sudo service docker restart   #restart a service
sudo service docker status   #status of a service
```

Thank you for reading :)

Priyanka Varshney
