A Step-by-Step Guide to Installing Jenkins on Ubuntu

A Step-by-Step Guide to Installing Jenkins on Ubuntu

Jenkins, an open-source automation server, plays a pivotal role in modern software development workflows. It automates the building, testing, and deployment of code, making the development process more efficient and reliable. In this step-by-step guide, we'll walk you through the process of installing Jenkins on an Ubuntu server. By the end of this tutorial, you'll have a Jenkins server up and running, ready to streamline your development pipeline.

Prerequisites

Before we dive into the installation process, here are the prerequisites:

  1. Ubuntu Server: You should have access to an Ubuntu server. We'll use an EC2 instance in this guide.

  2. SSH Access: Ensure that you have SSH access to your Ubuntu server.

Step 1: Create an EC2 Instance

create and connect to an EC2 instance. If you're not familiar with how to create and connect to an EC2 instance, you can refer to "How to Create and Connect to an EC2 Instance," for detailed step-by-step instructions. Once you have your EC2 instance ready, you can continue with the installation of Jenkins.

Step 2: Install Java

Jenkins is built on Java, so we need to install it first. Open a terminal and run the following command:

sudo apt-get install openjdk-11-jre

To confirm that Java is installed correctly, check its version with:

java --version

Step 3: Update the System

To ensure that your Ubuntu server is up to date, run the following command:

sudo apt-get update

Step 4: Installing Jenkins

Now, let's install Jenkins. Use the following commands:

wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt-get update
sudo apt-get install jenkins

To check the Jenkins version, use the following command:

jenkins --version

Step 5: Enable and Start Jenkins

Now, let's enable Jenkins to start on boot and start the service:

sudo systemctl enable jenkins
sudo systemctl start jenkins

Step 6: Setting up Jenkins

To configure Jenkins, access the web interface by opening your browser and navigating to:

http://your_server_ip_or_domain:8080

Getting the Initial Admin Password

To log in to Jenkins for the first time, you'll need to retrieve the initial admin password. This can be found on your server in the following location:

/var/lib/jenkins/secrets/initialAdminPassword

Use the cat command to display the password:

sudo cat /var/lib/jenkins/secrets/initialAdminPassword

Once you have the password, paste it into the Jenkins web interface.

Installing Plugins

Upon successful login, Jenkins will prompt you to install plugins. We recommend selecting the "Install suggested plugins" option, which will automatically install essential plugins for your Jenkins instance.

Creating the First Administrative User

After the plugin installation is complete, you'll be prompted to create the first administrative user. Follow the on-screen instructions to set up the admin user.

Step 7: Jenkins is Ready

Once you've completed the setup, you'll receive a confirmation page stating that "Jenkins is ready." Congratulations! Your Jenkins server is now up and running.

Bonus: Changing the Port Number

If you wish to change the default Jenkins port (8080) to a custom port like 8081, follow these steps:

  1. Modify the Jenkins configuration file:
sudo nano /etc/default/jenkins

Locate the line that begins with HTTP_PORT and change it to your desired port number, e.g., HTTP_PORT=8081.

  1. Save the file and exit the text editor.

  2. Restart the Jenkins service:

sudo systemctl restart jenkins
  1. Finally, access Jenkins using your modified port number in your browser:
http://your_server_ip_or_domain:8081

Conclusion

You've successfully installed Jenkins on your Ubuntu server, a crucial step towards streamlining your software development processes. Jenkins provides a powerful platform for automation, continuous integration, and continuous delivery (CI/CD). Now, you can start configuring Jenkins to build, test, and deploy your projects with ease.

Remember to explore Jenkins further, customize your pipelines, and explore plugins that suit your specific development needs. Jenkins offers a world of possibilities for optimizing your software development workflow.

Happy automating!

Did you find this article valuable?

Support Mantra Tech by becoming a sponsor. Any amount is appreciated!