How to Install Jenkins on Ubuntu 22.04 (Tutorial)

How to Install Jenkins on Ubuntu 22.04 (Tutorial). In this guide, we introduce Jenkins, its features, advantages and after navigate you through step by step tutorial to install it on Ubuntu 22.04.

First of all, many companies use Jenkins for accelerating the software development process. It is a popular server based application that not only helps build projects but also aids in monitoring and detecting errors in the early stages of the development process.

Shall we continue with the article How to Install Jenkins on Ubuntu 22.04 (Tutorial).

What is Jenkins?

Over the past few years, the need for reliable and useful apps has increased dramatically. Jenkins is one of the powerful open source automation software that fills the space and enables developers to build, test, and check for errors fast.

It is an open source automation server that is used to execute scripts in a continuous integration environment. The software offers a way to automate the process of building, testing, and deploying software.

Jenkins is an open source continuous integration server written in Java that runs on either a Windows or Linux operating system. Integrated with various other tools like GitHub, and many others for the automation of the process.

Moreover, Jenkins is a free tool that supports 1500+ plugins and offers various features that aid in the development, testing, and monitoring of software projects as well as in the Continuous Integration and continuous delivery (CI/CD) process.

In order to use Jenkins, all you need to do is create pipelines, a series of tools that help host, monitor, compile, and test codes and other changes made in the project.

Features of Jenkins

  • Quick installation – the self contained java based program is easy to install and run on Windows, macOS, and other operating systems.
  • Easy to configure – the built in help features and its excellent web interface help in setting up and configuring Jenkins easily without any hassle.
  • Supports multiple plugins – another best feature of Jenkins is it supports 1500+ plugins available in the update center. It also helps integrate with different tools and saves on overhead expenses.
  • Offers easy distribution – for quick development, testing, and platform deployments, Jenkins simply splits work over numerous platforms.
  • Supports Integration and Work DistributionJenkins can be used to build projects hosted in a number of version control systems including Git, Subversion, Mercurial, and ClearCase. Also supports the deployment of project artifacts to various targets like Hudson, JUnit, or Roo. Further, the open source continuous integration server helps in easy work distribution across different platforms.

Advantages of Jenkins

  • Powerful Open source Automation Tool: Simple to create, test, and deploy the most recent versions of any application because it is an open source programme. Users also receive updated versions with better updates, features, and advancements thanks to this capability. Jenkins is a Java based tool that is available for free download and has a web user interface that makes configuration simple for every non technical user. Further, the tool’s support for open source automation features expands the scope for creativity and participation in Jenkins initiatives.
  • Easy to Install and Configure: In comparison to other DevOps Tools available in the market, Jenkins is an open source continuous integration server that is much easy to install and configure. It can be installed on any operating system that supports Java, including Linux, macOS, and Microsoft Windows. With Jenkin’s inbuilt features and access to several plugins, developers quickly automate the process of deploying applications.

Features

  • Easy to use and run on different platforms: Jenkins’ adaptability, user friendliness, and compatibility with projects of all sizes are additional advantages. The simple to use DevOps tool supports more than 1500 plugins and has an open design. It additionally facilitates integration with a range of deployment technologies. Users also ask questions and learn about the technology in its strong and engaging community.
  • Offers API support: An integrated component of Jenkins called an API suite facilitates the retrieval of trustworthy data and aids in running validation tests on each web application.
  • Provides access to 1500+ plugins: It is a general purpose continuous integration server with many plugins available to support building and testing software projects continuously. With the help of these plugins, you can easily extend its functionality and can do more than just create projects.

We have arrived to the main part of the article How to Install Jenkins on Ubuntu 22.04 (Tutorial).

How to Install Jenkins on Ubuntu 22.04 (Tutorial)

Next section explains how to install Jenkins with Nginx as a reverse proxy on Ubuntu 22.04 server.

Prerequisites

  • An Ubuntu 22.04 server is installed on your system.
  • A root user or a user with sudo privileges.

Step 1 - Update the System

It is always a good idea to update all of your system packages to the latest version. You update all of them by running the following command.

				
					apt update -y
apt upgrade -y
				
			

After updating all the system packages, install other required dependencies using the following command.

				
					apt install curl debian-archive-keyring lsb-release ca-certificates apt-transport-https software-properties-common -y
				
			

Once all the dependencies are installed, you can proceed to install OpenJDK 11.

Step 2 - Install Java

Jenkins is a java based application. So, you will need to install Java on your server. You install it by just running the following command.

				
					apt install openjdk-11-jdk-headless -y
				
			

After the installation, you verify the Java version using the following command.

				
					java --version
				
			

You should get the Java version information in the following output.

				
					openjdk 11.0.17 2022-10-18
OpenJDK Runtime Environment (build 11.0.17+8-post-Ubuntu-1ubuntu222.04)
OpenJDK 64-Bit Server VM (build 11.0.17+8-post-Ubuntu-1ubuntu222.04, mixed mode, sharing)

				
			

Step 3 - Install Jenkins

By default, the Jenkins package is not included in the Ubuntu repository. So you will need to add the Jenkins repository to APT.

First, download the Jenkins GPG key with the following command.

				
					wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | gpg --dearmor -o /usr/share/keyrings/jenkins.gpg
				
			

Next, add the Jenkins repository to APT with the following command.

				
					sh -c 'echo deb [signed-by=/usr/share/keyrings/jenkins.gpg] http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
				
			

Once the repository is added, you can update the repository cache with the following command.

				
					apt update -y
				
			

Then, install the Jenkins package using the following command.

				
					apt install jenkins -y
				
			

Once the Jenkins package is installed, you can proceed to start the Jenkins service.

Step 4 - Manage Jenkins Service

By default, the Jenkins service is managed by systemd. You manage it easily using the systemctl command.

Let’s start the Jenkins service with the following command.

				
					systemctl start jenkins
				
			

Then, enable the Jenkins service so that it will start at system reboot.

				
					systemctl enable jenkins
				
			

Now verify the Jenkins status using the following command.

				
					systemctl status jenkins
				
			

You should see the following output.

				
					● jenkins.service - Jenkins Continuous Integration Server
Loaded: loaded (/lib/systemd/system/jenkins.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2023-01-06 04:51:11 UTC; 38s ago
Main PID: 82056 (java)
Tasks: 50 (limit: 4579)
Memory: 1.2G
CPU: 43.902s
CGroup: /system.slice/jenkins.service
└─82056 /usr/bin/java -Djava.awt.headless=true -jar /usr/share/java/jenkins.war --webroot=/var/cache/jenkins/war --httpPort=8080

Jan 06 04:50:53 linux jenkins[82056]: 9c920e0bc9524362878c5b457a19c9e6
Jan 06 04:50:53 linux jenkins[82056]: This may also be found at: /var/lib/jenkins/secrets/initialAdminPassword
Jan 06 04:50:53 linux jenkins[82056]: *************************************************************
Jan 06 04:50:53 linux jenkins[82056]: *************************************************************
Jan 06 04:50:53 linux jenkins[82056]: *************************************************************
Jan 06 04:51:11 linux jenkins[82056]: 2023-01-06 04:51:11.523+0000 [id=29] INFO jenkins.InitReactorRunner$1#onAttained: Complet>
Jan 06 04:51:11 linux jenkins[82056]: 2023-01-06 04:51:11.537+0000 [id=22] INFO hudson.lifecycle.Lifecycle#onReady: Jenkins is >
Jan 06 04:51:11 linux systemd[1]: Started Jenkins Continuous Integration Server.
Jan 06 04:51:11 linux jenkins[82056]: 2023-01-06 04:51:11.707+0000 [id=46] INFO h.m.DownloadService$Downloadable#load: Obtained>
Jan 06 04:51:11 linux jenkins[82056]: 2023-01-06 04:51:11.708+0000 [id=46] INFO hudson.util.Retrier#start: Performed the action>
lines 1-20/20 (END)

				
			

Jenkins is now installed and listens on port 8080. You can check it with the following command.

				
					ss -antpl | grep 8080
				
			

You should see the jenkins listening port in the following output.

				
					LISTEN 0 50 *:8080 *:* users:(("java",pid=82056,fd=8))
				
			

Step 5 - Configure Nginx as a Reverse Proxy

Next, you need to install and configure the Nginx as a reverse proxy for Jenkins. So you access Jenkins via port 80.

First, install the Nginx server package using the following command.

				
					apt install nginx -y
				
			

After installing Nginx, create an Nginx virtual host configuration file with the following command.

				
					nano /etc/nginx/conf.d/jenkins.conf
				
			

Add the following configurations.

				
					server {
listen 80;

server_name jenkins.example.com;

location / {
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://127.0.0.1:8080;
proxy_read_timeout 90;
proxy_http_version 1.1;
proxy_request_buffering off;
add_header 'X-SSH-Endpoint' 'jenkins.yourdomainname.com:50022' always;
}
}
				
			

Save and close the file then verify the Nginx for any syntax error with the following command.

				
					nginx -t
				
			

You should get the following output.

				
					nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

				
			

Next, restart the Nginx service to apply the changes.

				
					systemctl restart nginx
				
			

Now, edit the Jenkins configuration file and set listen address to localhost.

				
					nano /etc/default/jenkins
				
			

Change the following line:

				
					JENKINS_ARGS="--webroot=/var/cache/$NAME/war --httpPort=$HTTP_PORT --httpListenAddress=127.0.0.1"
				
			

Save and close the file then restart the Jenkins service to apply the changes.

				
					systemctl restart jenkins
				
			

Step 6 - Access Jenkins

First, retrieve the Jenkins root password using the following command.

				
					cat /var/lib/jenkins/secrets/initialAdminPassword
				
			

You will get the root password in the following output.

				
					9c920e0bc9524362878c5b457a19c9e6
				
			

Now, open your web browser and access Jenkins using the URL http://jenkins.example.com. You will be asked to provide the Jenkins password:

Provide your Jenkins root password then click on the Continue button. You should see the Customize Jenkins screen.

Click on “Install suggested plugins”. You should see the Jenkins admin user creation page.

Define your user details and click on the Save and Continue buttons. You should see the Jenkins instance configuration page.

Provide your Jenkins URL and click on the Save and Finish button. You should see the following screen.

Click on the Start using Jenkins. You should see the Jenkins dashboard on the following screen.

Thank you for reading How to Install Jenkins on Ubuntu 22.04 (Tutorial). We shall conclude. 

How to Install Jenkins on Ubuntu 22.04 (Tutorial) Conclusion

In this post, we have explained how to install Jenkins on Ubuntu 22.04. We also showed you how to configure Nginx as a reverse proxy for Jenkins. You can now create your first CI/CD pipeline using Jenkins to automate many tasks and makes the CI/CD pipeline tasks reliable.

Lastly, using the jenkins continuous integration tool, you deploy codes and detect errors at an early stage. The main advantage of Jenkins is that it provides a powerful set of features for automating the process of building and testing software projects continuously. 

Do explore more of Jenkins content, by checking our blog over here

Avatar for Hitesh Jethva
Hitesh Jethva

I am a fan of open source technology and have more than 10 years of experience working with Linux and Open Source technologies. I am one of the Linux technical writers for Cloud Infrastructure Services.

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x