How to change Jenkins Port number after installed Jenkins in ubuntu

We will guide you through the process of changing the port for the Jenkins service running on an Ubuntu server. By default, Jenkins runs on port 8080, but you can modify it to a different port of your choice. 


Let's try to change the port number for the Jenkins service by editing the systemd service unit file and setting the JENKINS_PORT environment variable. However, there are a few issues in your provided commands and configuration. Let me provide the corrected steps for changing the Jenkins port:

Check this below video for the process steps...


  1. Change Ownership of Jenkins Home Directory (if necessary): You can use the chown command to change the ownership of Jenkins's home directory:

    sudo chown -R jenkins:jenkins /var/lib/jenkins
  2. Stop Jenkins: Stop the Jenkins service:

    sudo systemctl stop jenkins
  3. Edit the Jenkins Service Unit File: Edit the Jenkins service unit file using a text editor. You should use a command like sudo nano /lib/systemd/system/jenkins.service. Here's an example of how to modify the unit file to set the Jenkins port:

    [Service]
    Environment="JENKINS_PORT=8443"

    After making this change, save the file and exit your text editor.

  4. Reload Systemd: Reload the systemd manager to pick up the changes you made to the unit file:

    sudo systemctl daemon-reload
  5. Start Jenkins: Start the Jenkins service:

    sudo systemctl start jenkins
  6. Check the Status: To verify that Jenkins is running without issues and using the new port, check its status:

    sudo systemctl status jenkins

    This should show that Jenkins is running and should reflect the new port configuration.

  7. Access Jenkins on the New Port: Finally, access Jenkins through a web browser using the new port. For example, if you set the port to 8443, you would access Jenkins at http://your_server_ip:8443.

Make sure to use the correct capitalization for "jenkins" when running systemctl status and other commands, as Linux is case-sensitive. In your provided commands, you used both "Jenkins" and "jenkins," and you should be consistent with the correct capitalization, which is "jenkins" in Ubuntu's service name.

Comments