Install Jenkins on Ubuntu in 10 Easy Steps
In this guide, we will walk you through the steps for installing and configuring Jenkins on a ubuntu server in 10 easy steps. Also, we have added the steps to install Jenkins using Docker on Ubuntu server.
Install and Configure Jenkins on Ubuntu
Follow the steps given below to install and configure Jenkins 2 on a ubuntu server.
Note: Centos/Rehat users follow this tutorial Install jenkins on centos/Redhat
Step 1: Log in to the server and update it.
sudo apt-get -y update
Step 2: Install open JDK 11.
sudo apt install openjdk-11-jdk -y
Step 3: Add the Jenkins Debian repo.
<code>wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -</code> <code>sudo sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'</code>
Step 4: Update the packages
sudo apt-get update -y
Step 5: Install latest LTS Jenkins.
sudo apt-get install jenkins -y
Step 6: Start the Jenkins service & enable it for starting during bootup.
sudo systemctl start jenkins sudo systemctl enable jenkins
You can check the status of Jenkins service using the following command.
sudo systemctl status jenkins
Step 7: Now you will be able to access the Jenkins server on port 8080 from localhost or using the IP address as shown below.
Step 8: As you can see in the above image, you need to provide the administrative password. You can get the password using the following command.
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Copy the password and click continue.
Step 9: Next, you will be asked to configure plugins as shown below. Select the “Install Suggested Plugins” option. This will install all the required plugins for building your projects. It will take a few minutes to install the plugins.
Step 10: Once installed, You need to create a user with password and click “save and finish”
Click “Start Using Jenkins” and it will take you to the Jenkins Dashboard. Log in using the username and password that you have given in step 8.
That’s it! Now you have a fully functional Jenkins server up and running. Consider setting up Jenkins backup using the backup plugin.
Here are some key configurations and file locations in Jenkins that you should know.
Note: For production setup, the recommended approach is to mount the Jenkins data folder to an additional data disk. This way you don’t lose any Jenkins data if the server crashes.
|Jenkins Data Location||/var/lib/jenkins|
|Jenkins main configuration file||/var/lib/jenkins/config.xml|
Next, would be the configuration of a distributed master-slave setup wherein you will have an active master and slave agents for building the projects.
Check Jenkins SSL setup guide if you want to setup SSL for your Jenkins instance.
Setting up Jenkins Using Docker on Ubuntu
If you are a docker user, you can run Jenkins on a docker container.
Refer docker installation document to install the latest edition of docker.
Execute the following command to deploy Jenkins on Docker
docker run -p 8080:8080 -p 50000:50000 --name jenkins jenkinsci/jenkins:latest
The above command won’t persist any changes if the container crashes. So it is better to mount a host volume to the container to hold all the Jenkins configurations.
Here is the command to deploy Jenkins container with the host volume mount.
docker run -p 8080:8080 -p 50000:50000 -v /home/ubuntu:/var/jenkins_home jenkinsci/jenkins:latest