# Creating Jenkins Server

Now creating the Jenkins server

<figure><img src="https://2022164620-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtzurpgroDJSMn9AFVmQP%2Fuploads%2FR6MJ5AepaGcwpNGe4pxm%2Fimage.png?alt=media&#x26;token=9ee31c69-2355-42e9-a89a-90c580cf131c" alt=""><figcaption></figcaption></figure>

t2.small

same security group

ssh into it then start running the following commands

First updating the packages



```sh
sudo apt update -y 

sudo apt install openjdk-11-jre -y 

Now installing Jenkins

sudo wget -O /usr/share/keyrings/jenkins-keyring.asc https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key

echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian-stable binary/ | sudo tee /etc/apt/sources.list.d/jenkins.list > /dev/null

sudo apt-get update -y 

sudo apt-get install jenkins -y

sudo systemctl enable jenkins
sudo systemctl start jenkins
sudo systemctl status jenkins 
```

<figure><img src="https://2022164620-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtzurpgroDJSMn9AFVmQP%2Fuploads%2FstI3OssrNZZn2reUSGNT%2Fimage.png?alt=media&#x26;token=c5ed9d9d-4d67-4399-8ded-9a4a30694014" alt=""><figcaption></figcaption></figure>

After Jenkins finishes installing we need to change the port since its default is 8080 and Tomcat is going to need that port.

#### You can change the port here:

```sh
sudo nano /etc/default/jenkins
```

scroll down to HTTP\_PORT=8080 and change it to 8082

After changing the port do not forget to restart jenkins

```sh
sudo systemctl restart jenkins
```

<figure><img src="https://2022164620-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtzurpgroDJSMn9AFVmQP%2Fuploads%2FR0EWp7rQY1wTICWkyaSq%2Fimage.png?alt=media&#x26;token=5b1507ea-4262-473e-8010-92e9b8023e66" alt=""><figcaption></figcaption></figure>

Now we can grab the public IP of the instance with the port 8082 and verify that Jenkins works.

If for some reason Jenkins is still working on port 8080 after you change it, do the following:

open the file `/usr/lib/systemd/system/jenkins.service`

search for the content "`Environment="JENKINS_PORT=8080`". Change the port number to your desired\
\
`sudo systemctl daemon-reload`\
\
`sudo systemctl restart jenkins.service`

<figure><img src="https://2022164620-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtzurpgroDJSMn9AFVmQP%2Fuploads%2FW1yWggazofaokJ16MB3L%2Fimage.png?alt=media&#x26;token=754fc48b-bff2-4c16-8fdd-8b03a441e381" alt=""><figcaption></figcaption></figure>

The password was provided initially but if you did not save it then, you can type

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

Enter the password and select Install suggested plugins.

<figure><img src="https://2022164620-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtzurpgroDJSMn9AFVmQP%2Fuploads%2F0e2HszZUtDCA2I4zkImc%2Fimage.png?alt=media&#x26;token=34e9b421-d9ee-4962-80ee-192a1767f11c" alt=""><figcaption></figcaption></figure>
