Yes, you can change the port Jenkins runs on. The default port is 8080, and you can switch it to any available port by editing the --httpPort argument in Jenkins' configuration file, or by passing it as a parameter when starting Jenkins from the command line. This article explains the exact steps for both methods, how to choose a new port, and how to fix common issues like port conflicts.
Why Change the Jenkins Port?
Jenkins uses port 8080 by default because it's a common choice for web applications, but that port is often already taken by another service on your server—like a different web server, a development tool, or another application. Changing the port lets you run Jenkins alongside those services without conflict. You might also want to use a non-standard port for security through obscurity, or to comply with your organization's network policy that restricts which ports are open.
Where Jenkins Stores Its Port Setting
Jenkins reads its HTTP port from the --httpPort argument in its initialization configuration. The exact file depends on how you installed Jenkins:
- Linux (systemd):
/etc/sysconfig/jenkins(on Red Hat/CentOS) or/etc/default/jenkins(on Debian/Ubuntu). Look for a line likeJENKINS_ARGS="--httpPort=8080". - Windows (service): The service configuration is stored in the Windows registry, but you can edit it via the
jenkins.xmlfile in the Jenkins installation directory (e.g.,C:\Program Files\Jenkins\jenkins.xml). Find the<arguments>tag and change the--httpPortvalue. - macOS (Homebrew): The configuration is in
/usr/local/opt/jenkins/homebrew.mxcl.jenkins.plist(or/opt/homebrewon Apple Silicon). Look for the--httpPortstring in theProgramArgumentsarray. - Docker: The port is mapped using the
-pflag when you run the container, e.g.,-p 8081:8080maps host port 8081 to the container's 8080. To change the Jenkins port itself, you'd need to override the--httpPortargument in the container's command.
How to Change the Port (Step-by-Step)
Here are the standard steps for the most common setups.
On Linux (systemd)
- Open the configuration file with a text editor (e.g.,
sudo nano /etc/default/jenkins). - Find the line that starts with
JENKINS_ARGS. It might look likeJENKINS_ARGS="--httpPort=8080". Change8080to your desired port, e.g.,--httpPort=9090. - Save the file and restart Jenkins:
sudo systemctl restart jenkins. - Verify the change by visiting
http://your-server:9090.
On Windows (Service)
- Open
jenkins.xmlas an administrator. - Find the
<arguments>element. It will contain a string like--httpPort=8080. Change the number. - Save the file and restart the Jenkins service (via Services.msc or
sc stop jenkinsthensc start jenkins).
On macOS (Homebrew)
- Edit the plist file:
sudo nano /usr/local/opt/jenkins/homebrew.mxcl.jenkins.plist. - Find the
<string>--httpPort=8080</string>line and change the port. - Reload the service:
brew services restart jenkins.
Running Jenkins from the Command Line (any OS)
If you start Jenkins manually with java -jar jenkins.war, simply add --httpPort=9090 to the command. For example:
java -jar jenkins.war --httpPort=9090
This is useful for testing or if you don't use a service manager.
How to Choose a New Port
When selecting a port, consider the following:
- Port numbers below 1024 require root/administrator privileges on Unix-like systems. Jenkins typically runs as a non-root user, so choose a port above 1024 (e.g., 8081, 9090, 8888).
- Check for conflicts: Before committing, run
netstat -tulpn | grep <port>(Linux) ornetstat -ano | findstr :<port>(Windows) to see if the port is already in use. - Firewall rules: If you have a firewall, you'll need to allow traffic on the new port. For example, on firewalld:
sudo firewall-cmd --permanent --add-port=9090/tcp && sudo firewall-cmd --reload. - Remember the URL: After changing the port, your Jenkins URL becomes
http://<hostname>:<newport>/. Update any bookmarks or scripts that reference the old port.
Common Problems and Fixes
Here are a few issues you might run into after changing the port.
Jenkins Fails to Start
If Jenkins doesn't start after the change, the most likely cause is that the new port is already in use. Check the Jenkins log file (usually /var/log/jenkins/jenkins.log on Linux) for an error like BindException: Address already in use. Choose a different port or free the conflicting one.
Can't Access Jenkins from Another Machine
If Jenkins is running but you can't reach it from a different computer, the issue is usually a firewall or security group. Ensure the new port is open in your OS firewall and, if you're on a cloud provider, in the network security group settings.
Jenkins Still Uses the Old Port
If Jenkins ignores your change, you might have edited the wrong file or there might be another configuration overriding it. Double-check that you edited the correct file for your installation type. Also, if you have a --httpPort specified in multiple places (like both the service file and a command line in a startup script), the last one wins.
Alternative: Using a Reverse Proxy
Instead of changing the port, many administrators keep Jenkins on 8080 and put a reverse proxy (like Nginx or Apache) in front of it. This lets you access Jenkins on port 80 (HTTP) or 443 (HTTPS) without changing Jenkins itself. The proxy forwards requests to localhost:8080. This approach is cleaner if you have multiple web applications on the same server, and it simplifies SSL configuration. However, it adds a layer of complexity and is not necessary if you just need a different port.
Frequently Asked Questions
What is Jenkins' default port?
Jenkins' default HTTP port is 8080. This is the port it listens on when you install it with the standard packages or run the WAR file without specifying a port.
Can I run Jenkins on port 80 without root?
On Linux, ports below 1024 require root privileges. If you want Jenkins to listen on port 80, you have two options: run Jenkins as root (not recommended for security), or use a reverse proxy like Nginx to listen on port 80 and forward to Jenkins on a higher port.
How do I change the port after Jenkins is already running?
You can't change the port of a running Jenkins instance without restarting it. The port is set at startup. You must edit the configuration file or command line, then restart Jenkins for the change to take effect.
What if I set the port to 0?
Setting --httpPort=0 makes Jenkins choose a random available port at startup. This is useful for testing, but not for a permanent setup because the port will change every time you restart Jenkins. The chosen port is printed in the Jenkins log.
Does changing the port affect my Jenkins jobs or plugins?
No, changing the port only affects how you access the web interface. Your jobs, build history, and configuration remain intact. However, if you have any scripts or webhooks that use the old URL, you'll need to update them.