Install Jenkins on Ubuntu and With Docker: Java 21, Unlock, Plugins, First Admin User and Reverse Proxy
Before You Install
| Item | Recommendation |
| Operating system | Ubuntu 22.04 or 24.04 (Debian, RHEL and Windows are also supported) |
| Memory | At least 2 GB for learning, 8 GB or more for a busy server |
| Disk | At least 20 GB. Build history and workspaces grow |
| Java | A supported Java 21 (or 25) runtime. Check the official Java support policy for the exact versions of the Jenkins release you install |
| Network | Port 8080 (default). Use HTTPS in front for real use |
Why Java 21? Current Jenkins LTS lines require Java 21 or 25. Older guides that tell you to install Java 11 or 17 are out of date and the controller will not start with an unsupported Java version.
Option 1: Install on Ubuntu (apt)
bash
# 1) Java
sudo apt-get update
sudo apt-get install -y fontconfig openjdk-21-jre
java -version
# 2) Jenkins LTS repository and key (check jenkins.io/doc/book/installing/linux for the current key file)
sudo wget -O /etc/apt/keyrings/jenkins-keyring.asc https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
echo "deb [signed-by=/etc/apt/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian-stable binary/" | sudo tee /etc/apt/sources.list.d/jenkins.list > /dev/null
# 3) Install and start
sudo apt-get update
sudo apt-get install -y jenkins
sudo systemctl enable --now jenkins
sudo systemctl status jenkins --no-pager
| Path | Purpose |
/var/lib/jenkins | JENKINS_HOME: configuration, jobs, plugins, secrets, workspaces. Back this up |
/var/log/jenkins/jenkins.log | Main log file |
/etc/default/jenkins or the systemd unit | Port and Java options (use systemctl edit jenkins) |
/usr/share/java/jenkins.war | The application |
The Setup Wizard
- Open
http://SERVER-IP:8080
- Jenkins asks for the initial admin password. Read it from the server:
- Choose Install suggested plugins (Git, Pipeline, credentials and more) and wait
- Create the first admin user (use a real password; do not keep the temporary one)
- Confirm the Jenkins URL (for example
https://jenkins.example.com/). Webhooks and links depend on it
bash
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Option 2: Run Jenkins in Docker
bash
docker volume create jenkins_home
docker run -d --name jenkins --restart unless-stopped \
-p 8080:8080 -p 50000:50000 \
-v jenkins_home:/var/jenkins_home \
jenkins/jenkins:lts-jdk21
docker logs -f jenkins # the initial admin password is printed here
docker exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword
yaml
# compose.yaml
services:
jenkins:
image: jenkins/jenkins:lts-jdk21
restart: unless-stopped
ports: ["8080:8080", "50000:50000"]
environment:
JAVA_OPTS: "-Xmx1g -Djenkins.install.runSetupWizard=true"
volumes:
- jenkins_home:/var/jenkins_home
volumes:
jenkins_home: {}
- Port 50000 is for inbound (JNLP/TCP) agents. If you only use WebSocket or SSH agents you can leave it closed
- Always use a volume for
/var/jenkins_home. Without it all jobs and settings vanish when the container is removed
- To update: pull the new image, remove the old container and start it again with the same volume
Put HTTPS in Front With nginx
text
server {
listen 443 ssl;
server_name jenkins.example.com;
ssl_certificate /etc/ssl/certs/jenkins.crt;
ssl_certificate_key /etc/ssl/private/jenkins.key;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_http_version 1.1;
proxy_request_buffering off; # large artifact uploads
proxy_read_timeout 90s;
}
}
After this, set the Jenkins URL to the HTTPS address under *Manage Jenkins, System*. If you see the warning *reverse proxy set up is broken*, the X-Forwarded-* headers or the Jenkins URL are wrong.
Tour of the Screen
| Area | Use |
| Dashboard | List of jobs and the build queue and executors panels |
| New Item | Create a job |
| Manage Jenkins | System settings, plugins, nodes, security, tools, credentials, system log |
| Build History | All builds across jobs |
| My Views | Group jobs into tabs |
| User menu (top right) | Your API token, credentials and personal settings |
Common Start-Up Problems
| Problem | Cause and fix |
| Service fails with Java error | Wrong Java version. Install Java 21 and run sudo update-alternatives --config java |
| Cannot open port 8080 | Firewall or cloud security group. Allow TCP 8080 (or your proxy port) |
| Port 8080 in use | Another service. Change with systemctl edit jenkins and Environment="JENKINS_PORT=8081" |
Please wait while Jenkins is getting ready forever | Low memory or plugin errors. Check journalctl -u jenkins -f |
| Plugin installation fails during the wizard | No internet access or proxy needed. Set the proxy in *Manage Jenkins, Plugins, Advanced* |
| Lost the admin password | Temporarily disable security in config.xml (lab only), or use the script console from a recovery procedure, then set a new password |
Practice Tasks
- Install Jenkins either on a VM or in Docker and finish the setup wizard
- Find
JENKINS_HOME and list its folders
- Read the logs and find the version number
- Put nginx in front with a self-signed certificate and fix the Jenkins URL
- Restart Jenkins from the UI using
/safeRestart and from the command line
Conclusion
Install a supported Java 21 runtime, add the official Jenkins LTS repository, start the service and complete the wizard with the initial admin password. In Docker, always mount a volume for /var/jenkins_home. For real use, put HTTPS in front with correct forwarded headers and set the Jenkins URL.
Quick Summary: Java 21; apt LTS repo; systemctl; initialAdminPassword; wizard; docker volume jenkins_home; ports 8080/50000; nginx headers; startup problems.