# How to Install Docker and Jenkins on Ubuntu Using Package Managers

Are you diving into the world of DevOps? Mastering tools like **Docker** and **Jenkins** is a crucial step toward building a seamless CI/CD pipeline. In this blog, I’ll walk you through how to install Docker and Jenkins on Ubuntu using package managers. Let's get started! 🛠️

---

## **Installing Docker on Ubuntu**

Docker is a powerful containerization tool that enables you to create, deploy, and manage lightweight, portable applications. Follow these steps to install Docker:

---

### **Step 1: Update the Package Index**

First, make sure your system is up-to-date by running:

```bash
sudo apt update
```

---

### **Step 2: Install Required Packages**

Install the necessary packages for apt to communicate with external repositories over HTTPS:

```bash
sudo apt install -y apt-transport-https ca-certificates curl software-properties-common
```

---

### **Step 3: Add Docker’s GPG Key**

Download and add Docker's official GPG key to ensure secure package downloads:

```bash
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
```

---

### **Step 4: Add Docker’s Repository**

Replace `<UBUNTU_VERSION>` with your Ubuntu version (e.g., `focal`, `jammy`):

```bash
echo "deb [arch=$(dpkg --print-architecture) 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 the Package Index Again**

Refresh the package index to include the newly added Docker repository:

```bash
sudo apt update
```

---

### **Step 6: Install Docker**

Install Docker Community Edition (CE) and its components:

```bash
sudo apt install -y docker-ce docker-ce-cli containerd.io
```

---

### **Step 7: Verify Docker Installation**

Check if Docker is installed by running:

```bash
docker --version
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1732969806994/9096a9b3-64a6-4a31-9624-dafeef91b785.png align="center")

---

### **Step 8 (Optional): Manage Docker as a Non-Root User**

To avoid using `sudo` with Docker commands, add your user to the Docker group:

```bash
sudo usermod -aG docker $USER && newgrp docker
```

Log out and log back in for changes to take effect.

---

### **Step 9: Test Docker Installation**

Run a test container to confirm Docker is working properly:

```bash
docker run hello-world
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1732969855707/6d40deb4-3c67-4c5b-a696-f0acb2c61463.png align="center")

---

## **Installing Jenkins on Ubuntu**

Jenkins is an open-source automation server widely used for CI/CD. Here’s how you can install it on your system:

---

### **Step 1: Install Java**

Jenkins requires Java. Install OpenJDK 17 with the following commands:

```bash
sudo apt install openjdk-17-jre -y
java -version
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1732969917163/5e85bd94-3aef-43ca-95b4-60d5fe6a15f9.png align="center")

---

### **Step 2: Install Dependencies**

Install the required dependencies for Jenkins:

```bash
sudo apt-get install -y ca-certificates curl gnupg
```

---

### **Step 3: Add Jenkins GPG Key**

Add the GPG key for Jenkins to your system:

```bash
curl -fsSL https://pkg.jenkins.io/debian/jenkins.io-2023.key | sudo tee /usr/share/keyrings/jenkins-keyring.asc > /dev/null
```

---

### **Step 4: Add Jenkins Repository**

Add the Jenkins repository to your system:

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

---

### **Step 5: Update the Package Index**

Refresh the package list to include the Jenkins repository:

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

---

### **Step 6: Install Jenkins**

Install Jenkins using the command:

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

---

### **Step 7: Enable and Start Jenkins**

Enable Jenkins to start automatically on boot and start the Jenkins service:

```bash
sudo systemctl enable jenkins
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1732969983991/dc875f04-d556-4a8f-8fcb-1edbba197474.png align="center")

---

### **Step 8: Verify Jenkins Installation**

Check the status of Jenkins to ensure it is running:

```bash
sudo systemctl status jenkins
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1732970011882/8d3874dc-587d-4f51-9fd5-cd3349b50251.png align="center")

### **Step 9: Verify Jenkins Installation in browser also**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1732970594921/216730ce-aa34-497b-b1c3-a48f1ffc52e6.png align="center")

---

## **Conclusion**

You’ve successfully installed **Docker** and **Jenkins** on your Ubuntu system! 🎉

Docker will help you containerize your applications, while Jenkins will streamline your CI/CD workflows. Combine these tools to create an efficient and scalable development environment.

### **What's Next?**

Dive deeper into:

* Setting up your first Jenkins pipeline.
    
* Using Docker in Jenkins for automated builds.
    
* Exploring advanced Docker networking and volumes.
    

Stay tuned for more DevOps tutorials. Got questions? Drop them in the comments below! 😊
