# Jenkins Build EC2 Ubuntu

![](https://3776180966-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LgLv25e2BrxRC5m6flh%2F-LjUUCKTPMD7pe9Ttwtv%2F-LjUUYg0N85pxx_506bg%2FScreen%20Shot%202019-07-11%20at%2010.55.09%20AM.png?alt=media\&token=e69d6d4e-4a53-4c4a-b744-f73536b07049)

[Jenkins](https://jenkins.io/) is an open source automation server that offers an easy way to set up a continuous integration and continuous delivery (CI/CD) pipeline.

Continuous integration (CI) is a DevOps practice in which team members regularly commit their code changes to the version control repository, after which automated builds and tests are run. Continuous delivery (CD) is a series of practices where code changes are automatically built, tested and deployed to production.

In this tutorial, we will show you how to install Jenkins on an Ubuntu 18.04 machine using the Jenkins Debian package repository.

Although this tutorial is written for Ubuntu 18.04 Bionic Beaver the same steps can be used for Ubuntu 16.04 Xenial Xerus.

### [Prerequisites](https://linuxize.com/post/how-to-install-jenkins-on-ubuntu-18-04/#prerequisites) <a href="#prerequisites" id="prerequisites"></a>

Before continuing with this tutorial, make sure you are logged in as a [user with sudo privileges](https://linuxize.com/post/how-to-create-a-sudo-user-on-ubuntu/).

### [Installing Jenkins](https://linuxize.com/post/how-to-install-jenkins-on-ubuntu-18-04/#installing-jenkins) <a href="#installing-jenkins" id="installing-jenkins"></a>

To install Jenkins on your Ubuntu system, follow these steps:

Create EC2 Ubuntu Instance and do ssh there&#x20;

`ssh -i "pemfile.pem" root@ec2-6.6.6.compute-1.amazonaws.com`

1. Install Java on ec2 instance as Jenkins need it&#x20;

   Since Jenkins is a Java application, the first step is to install Java. Update the package index and install the Java 8 OpenJDK package with the following commands:

   ```
   sudo apt updatesudo apt install openjdk-8-jdk
   ```

   The current version of Jenkins does not support Java 10 (and Java 11) yet. If you have multiple versions of Java installed on your machine [make sure Java 8 is the default Java version](https://linuxize.com/post/install-java-on-ubuntu-18-04/).
2. Add the Jenkins Debian repository.

   Import the GPG keys of the Jenkins repository using the following [`wget`](https://linuxize.com/post/wget-command-examples/) command:

   ```
   wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
   ```

   The command above should output `OK` which means that the key has been successfully imported and packages from this repository will be considered trusted.

   Next, add the Jenkins repository to the system with:

   ```
   sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
   ```
3. Install Jenkins.

   Once the Jenkins repository is enabled, update the `apt` package list and install the latest version of Jenkins by typing:

   ```
   sudo apt updatesudo apt install jenkins
   ```

   Jenkins service will automatically start after the installation process is complete. You can verify it by printing the service status:

   ```
   systemctl status jenkins
   ```

   You should see something similar to this:

   ```
   ● jenkins.service - LSB: Start Jenkins at boot time
   Loaded: loaded (/etc/init.d/jenkins; generated)
   Active: active (exited) since Wed 2018-08-22 13:03:08 PDT; 2min 16s ago
       Docs: man:systemd-sysv-generator(8)
       Tasks: 0 (limit: 2319)
   CGroup: /system.slice/jenkins.service
   ```

### [Adjusting Firewall](https://linuxize.com/post/how-to-install-jenkins-on-ubuntu-18-04/#adjusting-firewall) <a href="#adjusting-firewall" id="adjusting-firewall"></a>

If you are installing Jenkins on a remote Ubuntu server that is protected by a firewall you’ll need to open port `8080`. Assuming you are using [`UFW`](https://linuxize.com/post/how-to-setup-a-firewall-with-ufw-on-ubuntu-18-04/) to manage your firewall, you can open the port with the following command:

```
sudo ufw allow 8080
```

Verify the change with:

```
sudo ufw status
```

```
Status: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere
8080                       ALLOW       Anywhere
OpenSSH (v6)               ALLOW       Anywhere (v6)
8080 (v6)                  ALLOW       Anywhere (v6
```

### [Setting Up Jenkins](https://linuxize.com/post/how-to-install-jenkins-on-ubuntu-18-04/#setting-up-jenkins) <a href="#setting-up-jenkins" id="setting-up-jenkins"></a>

To set up your new Jenkins installation, open your browser, type your domain or IP address followed by port `8080`, `http://your_ip_or_domain:8080` and screen similar to the following will be displayed:![](https://linuxize.com/post/how-to-install-jenkins-on-ubuntu-18-04/unlock-jenkins_huff7c186b4c9370e26f4ba03e0bde0db7_51753_600x0_resize_q75_box.jpg)

During the installation, the Jenkins installer creates an initial 32-character long alphanumeric password. Use the following command to print the password on your terminal:

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

```
2115173b548f4e99a203ee99a8732a32
```

Copy the password from your terminal, paste it into the Administrator password field and click `Continue`.![](https://linuxize.com/post/how-to-install-jenkins-on-ubuntu-18-04/customize-jenkins_hu1cb104bb89f767fdac96ebfecc6c04d0_53686_600x0_resize_q75_box.jpg)

On the next screen, the setup wizard will ask you whether you want to install suggested plugins or you want to select specific plugins. Click on the `Install suggested plugins` box, and the installation process will start immediately.![](https://linuxize.com/post/how-to-install-jenkins-on-ubuntu-18-04/jenkins-getting-started_hu4965eddf303984f869a67fd6fe23ee72_63429_600x0_resize_q75_box.jpg)

Once the plugins are installed, you will be prompted to set up the first admin user. Fill out all required information and click `Save and Continue`.![](https://linuxize.com/post/how-to-install-jenkins-on-ubuntu-18-04/jenkins-create-admin-user_hude9803b4cc603eb2b5f73825b5379854_36992_600x0_resize_q75_box.jpg)

The next page will ask you to set the URL for your Jenkins instance. The field will be populated with an automatically generated URL.![](https://linuxize.com/post/how-to-install-jenkins-on-ubuntu-18-04/jenkins-instance-configuration_hue0590329ea505a29a79bdaa150b05990_50390_600x0_resize_q75_box.jpg)

Confirm the URL by clicking on the `Save and Finish` button and the setup process will be completed.![](https://linuxize.com/post/how-to-install-jenkins-on-ubuntu-18-04/jenkins-is-ready_hu3da675c8f3b82e406e68ceb52ab60309_26265_600x0_resize_q75_box.jpg)

Click on the `Start using Jenkins` button and you will be redirected to the Jenkins dashboard logged in as the admin user you have created in one of the previous steps.![](https://linuxize.com/post/how-to-install-jenkins-on-ubuntu-18-04/jenkins-homepage_hu004045fc7e4b3d755da189b614961948_43272_600x0_resize_q75_box.jpg)

At this point, you’ve successfully installed Jenkins on your system.

![](https://3776180966-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LgLv25e2BrxRC5m6flh%2F-LjUUCKTPMD7pe9Ttwtv%2F-LjUV70-O6hcNCXuVNN4%2FScreen%20Shot%202019-07-11%20at%2010.53.01%20AM.png?alt=media\&token=7761b992-3bf3-4f0e-9d3c-3c0c3052f56b)

![](https://3776180966-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LgLv25e2BrxRC5m6flh%2F-LjUUCKTPMD7pe9Ttwtv%2F-LjUVoqNtuNRbzdsDHvq%2FScreen%20Shot%202019-07-11%20at%2011.00.39%20AM.png?alt=media\&token=2558ea1a-b1bf-4658-905d-3651436520bf)

Lets run the application build using Jenkins CI which is running on EC2 Ubuntu Instance&#x20;

### **Install Jenkins Plugins**

At the Jenkins home page on the left menu select *Manage Jenkins -> Manage Plugins* select the tab *Available* and search for the following plugins:

* [Blue Ocean](https://jenkins.io/projects/blueocean/) - New Jenkins UI
* [Pipeline AWS](https://plugins.jenkins.io/pipeline-aws) - AWS Integration

### Let' s Add Node.js also on server

Node.js package is available in LTS release and the current release. It’s your choice to select which version you want to install on the system as per your requirements. Let’s add the PPA to your system to install Nodejs on Ubuntu.

**Use Current Release:** At te last update of this tutorial, Node.js 12 is the current Node.js release available.

```
sudo apt-get install curl python-software-properties
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
```

**Use LTS Release :** At the last update of this tutorial, Node.js 10.15.3 is the LTS release available.

```
sudo apt-get install curl python-software-properties
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
```

For this tutorial, **I am using the latest current release** and added their PPA to my system.

### Step 2 – Install Node.js on Ubuntu

You can successfully add Node.js PPA to Ubuntu system. Now execute the below command install Node on and Ubuntu using apt-get. This will also install NPM with node.js. This command also installs many other dependent packages on your system.

```
sudo apt-get install nodejs
```
