How to Install Jenkins on Ubuntu 20.04?

how to install jenkins on ubuntu 20.04

In today’s world of software development, Continuous Integration (CI) is a fundamental practice that ensures developers can frequently integrate code changes into a shared repository. One of the most popular CI tools is Jenkins. Jenkins automates the build, test, and deployment process, enabling teams to release software faster and more reliably.

If you’re using Ubuntu 20.04 and want to set up Jenkins, you’re in the right place. In this guide, we’ll walk you through the process of install Jenkins on Ubuntu 20.04 from scratch. Whether you’re completely new to Jenkins or just need a refresher, this tutorial will give you the step-by-step guidance you need to get Jenkins running on your system.

By the end of this article, you’ll have Jenkins installed and ready to help you automate your software workflows.

What is Jenkins?

Jenkins is an open-source automation server written in Java. It’s widely used for automating tasks related to building, testing, and deploying software. Jenkins supports various version control systems (e.g., Git, Subversion) and can be integrated with numerous plugins to enhance its functionality.

Key features of Jenkins include:

  • Extensibility: Jenkins offers a vast library of plugins for various integrations and extensions.
  • Frequent Builds: Jenkins allows developers to automate and schedule builds, ensuring code is always up-to-date.
  • Distributed Builds: Jenkins can distribute workloads across multiple machines, making it highly scalable.

With its ability to automate repetitive tasks and integrate with multiple development tools, Jenkins plays a crucial role in modern software development pipelines.

Why Use Jenkins for Continuous Integration?

Continuous Integration (CI) is a practice that ensures code is built, tested, and deployed as soon as it is committed to the source code repository. Jenkins plays a central role in implementing CI, offering numerous benefits:

  • Faster Development Cycle: Jenkins automates the process of building and testing software, ensuring that developers receive immediate feedback on their code changes.
  • Improved Code Quality: Automated testing allows developers to identify bugs early in the development cycle, reducing the chances of critical issues in production.
  • Collaboration: Jenkins integrates with various communication tools and platforms like Slack, GitHub, and Jira, making it easier for teams to collaborate and stay updated on project progress.

With its open-source nature and extensive plugin ecosystem, Jenkins is an excellent tool for teams looking to implement a continuous integration pipeline.

how to install jenkins on ubuntu 20.04

Prerequisites for Install Jenkins on Ubuntu 20.04

Before installing Jenkins on Ubuntu 20.04, ensure that you meet the following prerequisites:

  1. Ubuntu 20.04 System: Ensure you are using Ubuntu 20.04 or later.
  2. Java Development Kit (JDK): Jenkins requires Java to run, so you need to have a compatible version of JDK installed.
  3. Root or Sudo Access: You need root or sudo privileges to install Jenkins and configure the system.
  4. Internet Connection: Jenkins will be installed from the official repository, so you need a stable internet connection.

Once you’ve confirmed these prerequisites, you’re ready to begin the installation process.

Step 1: Update Your Ubuntu System

It’s always a good practice to ensure your system is up to date before installing new software. Run the following commands to update your system:

sudo apt update
sudo apt upgrade -y

The update command will refresh the package list, while upgrade ensures your system is running the latest versions of installed packages.


Step 2: Install Java Development Kit (JDK)

Jenkins requires Java to function. The recommended version for Jenkins is OpenJDK 11. To install OpenJDK 11 on Ubuntu 20.04, use the following commands:

  1. Install OpenJDK 11: sudo apt install openjdk-11-jdk -y
  2. Verify the Installation: After installation, verify that Java is installed by checking its version: java -version You should see output similar to this: openjdk version "11.0.11" 2021-04-20 OpenJDK Runtime Environment (build 11.0.11+9-Ubuntu-0ubuntu2) OpenJDK 64-Bit Server VM (build 11.0.11+9-Ubuntu-0ubuntu2, mixed mode)

Step 3: Install Jenkins on Ubuntu 20.04

Now that Java is installed, you can proceed with installing Jenkins. The most reliable method to install Jenkins is by adding the official Jenkins repository and installing it using apt.

Add the Jenkins Repository

  1. Add the Jenkins repository key: First, add the Jenkins repository key to your system: wget -q -O - https://pkg.jenkins.io/keys/jenkins.io.key | sudo tee /usr/share/keyrings/jenkins-archive.key
  2. Add the Jenkins repository: Add the Jenkins repository to your system: sudo sh -c 'echo deb [signed-by=/usr/share/keyrings/jenkins-archive.key] https://pkg.jenkins.io/debian/ stable main > /etc/apt/sources.list.d/jenkins.list'
  3. Update the package index: Run the following command to update your package list to include the Jenkins repository: sudo apt update
  4. Install Jenkins: Finally, install Jenkins using apt: sudo apt install jenkins -y

This will install Jenkins and all necessary dependencies.


Step 4: Start and Enable Jenkins Service

Once Jenkins is installed, you need to start the Jenkins service and ensure it runs automatically at system boot.

  1. Start Jenkins: sudo systemctl start jenkins
  2. Enable Jenkins to start on boot: sudo systemctl enable jenkins
  3. Check Jenkins status: To verify that Jenkins is running properly, you can check its status: sudo systemctl status jenkins

If Jenkins is running, you should see output indicating that Jenkins is active and running.


Step 5: Access Jenkins Web Interface

Jenkins provides a web-based interface that you can access through your browser. By default, Jenkins runs on port 8080.

  1. Open your browser and navigate to the following URL: http://localhost:8080 If you’re accessing Jenkins from another machine, replace localhost with the IP address of your Ubuntu server.

Step 6: Unlock Jenkins

The first time you access Jenkins, you’ll be prompted to unlock it using a secret key.

  1. Find the unlock key: The key is stored in a file located at /var/lib/jenkins/secrets/initialAdminPassword. You can retrieve it by running the following command: sudo cat /var/lib/jenkins/secrets/initialAdminPassword
  2. Enter the unlock key: Copy the key displayed in the terminal and paste it into the web interface to unlock Jenkins.

Step 7: Set Up Jenkins

After unlocking Jenkins, you’ll be guided through the initial setup process.

  1. Install Suggested Plugins: Jenkins will prompt you to install plugins. Choose the option to install Suggested Plugins, as this will install most of the common tools you’ll need.
  2. Create an Admin User: After the plugins are installed, you’ll be asked to create an admin user. Fill in the required details, including username, password, and email address.
  3. Complete Setup: Once the setup is complete, you can start using Jenkins to configure and create new projects.

How to Install Plugins in Jenkins?

Jenkins offers a vast repository of plugins that can be installed to extend its functionality. To install plugins:

  1. Go to the Manage Jenkins page.
  2. Click on “Manage Plugins”.
  3. Navigate to the Available tab.
  4. Search for the desired plugin and click Install.

Troubleshooting Common Issues with Jenkins Installation

  • Jenkins is not starting: Ensure that your system meets the requirements, and check the Jenkins logs for errors: sudo journalctl -u jenkins
  • Unable to access Jenkins web interface: Ensure that the firewall is not blocking port 8080. You can open the port using: sudo ufw allow 8080
  • Plugin installation errors: If plugins fail to install, check your internet connection and verify that the Jenkins repository is up to date.

Conclusion

Install Jenkins on Ubuntu 20.04 is a straightforward process that can greatly improve your software development and deployment pipeline. By following the steps in this guide, you should have Jenkins up and running in no time, ready to automate your CI/CD workflows.

Now that you have Jenkins installed, it’s time to explore its full potential. Configure your first Jenkins job, integrate with Git repositories, and start automating builds and deployments.

If you found this guide helpful, share it with your colleagues or leave a comment below with any questions. Don’t forget to explore our other articles on Jenkins and DevOps best practices!

Read Also : How to Install deb File on Ubuntu 20.04?

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top