In this post we will install Jenkins on Ubuntu 18.04 LTS server. For installing the Jenkins, we will use ‘Generic Java Package (war)’. Jenkins is very popular automation server widely use for building,deploying and automating the projects.
It is one of the Open Source Software which is mostly prefer for CI/CD. There are lots of Jenkins plugins available which helps to enhance the function and features.
Hardware and Software Requirements For Jenkins
In this section, we will list Hardware and Software requirements both for installing and managing the Jenkins.
Recommended Hardware Configuration
This is recommended hardware requirements to start with small team. As your requirement grows you have to increase the hardware specs.
- 1GB RAM or more
- 50GB or more disk space
Software Prerequisites For Installing Jenkins (war)
- Jenkins Stable LTS version 2.138.x [Generic Java Package (war)]
- Java version 8
- Only Java 8 is supported (Both 32 and 64 bit)
- Older than Java 8 is not supported
- Java 9 is not supported
- Java 10 and 11 has preview support
Steps To Install Jenkins On Ubuntu 18.04 LTS Server
In this section, we are installing Jenkins on Ubuntu 18.04 LTS server. It will be standalone Jenkins server. We always recommend to use LTS(Long Term Support) version for any Operating System or software because it provides support for longer period of time.
Install Java
In this section, we are installing Java and then we will set Java environment.
- Login to server
- Create directory:
sudo mkdir -p /opt/java
- Download Java:
curl -L -b "oraclelicense=a" https://download.oracle.com/otn-pub/java/jdk/8u192-b12/750e1c8617c5452694857ad95c3ee230/jdk-8u192-linux-x64.tar.gz -O
- Untar Downloaded Java Package:
sudo tar -xvzf jdk-8u192-linux-x64.tar.gz -C /opt/java/
- Rename Directory:
sudo mv /opt/java/jdk1.8.0_192/ /opt/java/jdk8
Set Java Environment
Now set the Java environment.
- Create New Profile Script: We use vi/vim. Use your favorite file editor.
sudo vi /etc/profile.d/java.sh
And write following contents in script and save the file.
export JAVA_HOME=/opt/java/jdk8 export PATH=/opt/java/jdk8/bin:$PATH
- Change the script permission:
sudo chmod +x /etc/profile.d/java.sh
- Immediate Java Environment Effect: After setting Java Environment, to make it effective either logout and login again.
Alternatively, you can also run thesource
command like this.sudo source /etc/profile.d/java.sh
- Check Java version:
java -version
Example from our system.
root@server01:/home/user1# java -version java version "1.8.0_192" Java(TM) SE Runtime Environment (build 1.8.0_192-b12) Java HotSpot(TM) 64-Bit Server VM (build 25.192-b12, mixed mode) root@server01:/home/user1#
Create User For Jenkins
We will create user which will be used by Jenkins Application.
- Create user called jenkins and change its shell to bash:
useradd -d /home/jenkins -m jenkins sudo usermod -s /bin/bash jenkins
Install Jenkins by using java war file
In this section, we will use Generic Java war file for installing Jenkins. Always use LTS version.
- Create directory for keeping Jenkins war file:
sudo mkdir -p /opt/jenkins
- Download Jenkins war file to /opt/jenkins directory:
wget http://mirrors.jenkins.io/war-stable/latest/jenkins.war -P /opt/jenkins/
- Change owner,group and permission of jenkins war file
sudo chown jenkins:jenkins /opt/jenkins/jenkins.war sudo chmod +x /opt/jenkins/jenkins.war
- Switch to Jenkins user
sudo su - jenkins
- Execute Jenkins war file:
This is important step, when we first time execute the jenkins war file and all goes well then at the end of output it will show temporary jenkin’s admin password which also saved in the file.Execute the Jenkins war file.
$java -jar /opt/jenkins/jenkins.war
- Get Jenkins admin initial temporary password:
Wait for execution process to reach at the point when you found this line “INFO: Jenkins is fully up and running”You will also find the temporary initial admin password for Jenkins, copy the password. Here is the sample output.
************************************************************* ************************************************************* Jenkins initial setup is required. An admin user has been created and a password generated. Please use the following password to proceed to installation: 840b0ca4d88841d299ab48e2d8a48c02 This may also be found at: /home/jenkins/.jenkins/secrets/initialAdminPassword ************************************************************* *************************************************************
- Further installation from Web Interface
In web browser’s address field type Jenkins server ip address or FQDN and use port 8080 to open.
Jenkins by-default run on port number 8080 (For example http://192.168.123.247:8080).Note:
ip addr list
command will show your server ip address.Rest of the installation process is very simple and by reading instruction on screen you can easily complete the setup.
- Give temporary admin password which you have got from Step 6. ( Do not use our one, the temporary admin password should be generated in your system on doing Step 6)
- Click on “Install Suggested Plugins”, it will by-default install all plugins suggested by Jenkins. You can also select a few plugins, for this you have to click “Select plugins to install”
We recommend to go for “Install Suggested Plugins”.
-
Give Jenkins Admin user name and set its password as per your wish. We recommend to set password containing Alphanumeric Characters because it is a good security practice.
Click “Save and Continue” button after setting Jenkin’s admin username and password.
- You will see Jenkins URL information on screen. Click “Save and Finish”.
-
In next screen, you will see “Jenkins is ready!”. Quite obvious click on “Start Using Jenkins”
- Immediate after click, you will be login to Jenkins Admin Console. You will get first screen of Jenkins.
Now it will start installing the plugins as shown in given below screenshot.
In next step we will create Jenkins systemd script. Press CTRL+C on terminal where you have executed the Jenkins war file to run the process.
Create systemd script for Jenkins
Logout from jenkins user shell (Press CTRL+D or type command exit
)
- Create Jenkins system script file
- Give Permission
sudo chmod 755 /etc/systemd/system/jenkins.service
- Reload Systemd Daemon:
sudo systemctl daemon-reload
- Manage Jenkins Service: After creating Jenkins systemd script, you can easily manage the Jenkins service.
# To start jenkins service
sudo systemctl start jenkins
# To stop jenkins service
sudo systemctl stop jenkins
# To restart jenkins service
sudo systemctl restart jenkins
# To check status of jenkins service
sudo systemctl status jenkins
# To enable jenkins service to run at booting time
sudo systemctl enable jenkins
# To disable jenkins service to run at booting time
sudo systemctl disable jenkins
sudo vi /etc/systemd/system/jenkins.service
Write the below given contents in file jenkins.service
[Unit] Description=Jenkins Daemon [Service] ExecStart=/opt/java/jdk8/bin/java -jar /opt/jenkins/jenkins.war User=jenkins [Install] WantedBy=multi-user.target
I hope now you are able to run your Jenkins server. To update/upgrade Jenkins or its plugins you can do directly from its admin console and for this you receive notification on admin console (by-default).