🌟Install Jenkins in Windows Subsystem for Linux (WSL2)
Tags: jenkins, wsl, wsl2, cicd
Published: 2021-05-24 10:59:59

# Jenkins

Jenkins is one of the most popular tools DevOps tools, originally designed with one purpose in mind: be a great build automation server. It’s free and open-source, built for developers, and has lots and lots of plugins that you can configure to build anything.

Although Jenkins can be deployed to lots of public clouds like AWS, GCP or Azure, running a local Jenkins server still has its own advantages and values. Speeds and easy for experimentation are just two of the most important ones.

# Windows Subsystem for Linux

The Windows Subsystem for Linux **(WSL)** lets developers run a GNU/Linux environment -- including most command-line tools, utilities, and applications -- directly on Windows, unmodified, without the overhead of a traditional virtual machine or dual-boot setup.

**WSL 2** is a new version of the Windows Subsystem for Linux architecture that powers the Windows Subsystem for Linux to run **ELF64 Linux** binaries on Windows. Its primary goals are to increase file system performance, as well as adding full system call compatibility.

# Install WSL2 on Windows

For the full instructions to install WSL2 on windows, refer to [this link](https://dev.to/davidkou/running-docker-in-windows-subsystem-for-linux-wsl2-1k43) or [this one](https://docs.microsoft.com/en-us/windows/wsl/install-win10)

# Mix together: Install Jenkins in Windows Subsystem for Linux

This blog will focus on putting all the nice stuffs together: Windows + Ubuntu + Jenkins.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4rscqtxuthtw2oclevds.png)
  


### Open a terminal in Windows

Open a new Ubuntu terminal (I am using Windows Terminal, but you can use whatever terminal tools like blow excellent candidates)
- [Cmder](https://cmder.net/)
- [Fluent Terminal](https://github.com/felixse/FluentTerminal)
- [Windows Terminal](https://github.com/microsoft/terminal)

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/49bclg1uzb9st3ws7fnq.png)
 
### Update Ubuntu in WSL2

Below here are the quick scripts for updating Ubuntu in WSL2:

```
sudo -s
apt-get update
apt-get -y install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
apt-get update
```

### Install Java and Jenkins in WSL2

```
sudo apt install openjdk-8-jdk           # choose this or next line
sudo apt install openjdk-11-jre-headless # or Install Java 11 JDK/JRE
sudo apt install Jenkins
```
You will get an error like below:

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o3h94fb5d8ec8awf5gzx.png)
 
To solve this, run the below script:

```
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add
sudo bash -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt update
sudo apt-get install jenkins
```
With this, ~ 68MB Jenkins package will be downloaded, it will take a while depending on the internet speeds.

### Update Firewall to enable Jenkins service

```
sudo ufw enable
sudo ufw allow 8080 # whatever port number you like
```

Check the status of your port:
```
sudo ufw status
```

### Run Jenkins server
```
sudo service jenkins start
```

### Install Jenkins from a browser

Navigate to your host browser, and type:

```
http://localhost:8080/
```

You will see the screen as below:

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/evt3a4ij9juvu0vhalku.png)

where you will be prompted to provide an initial password to unlock Jenkins.

Follow up the screen instructions and in the terminal, type below:
```
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
```
- Copy the password you retrieved to clipboard
![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o1gr5hjea85rlhku5hn4.png)
 
- Return to the host browser window, and paste the password therein
- Click "Continue" button!


Follow the screen instructions to create an account. Hooray!

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k0qhxcfvw79jan0gt464.png)