GitBucket is an open-source Git platform similar to GitHub, written in Scala, that allows you to manage Git repositories on your own server. In this guide, we will walk you through how to install GitBucket with Nginx as a reverse proxy on Ubuntu 20.04 LTS. This setup works well whether you’re using a Windows VPS UK or other VPS hosting environments.
Prerequisites
Before starting, ensure you have the following:
- An Ubuntu 20.04 LTS server, which could be hosted on a UK Windows VPS, Windows Virtual Private Servers, or another Windows VPS Hosting UK environment.
- Root or sudo privileges on your server.
- A domain name pointing to your server's IP address (optional but recommended).
Step 1: Update Your System
Start by updating your system packages to ensure everything is up to date. Run the following command:
sudo apt update && sudo apt upgrade
Step 2: Install Java (OpenJDK)
GitBucket requires Java to run. Install OpenJDK 11 with the following command:
sudo apt install openjdk-11-jdk -y
After installation, verify that Java is installed by running:
java -version
You should see the version output for OpenJDK 11.
Step 3: Install GitBucket
Next, download the latest version of GitBucket from the official website. Navigate to your home directory and use wget
to download the GitBucket WAR file:
cd /opt
sudo wget https://github.com/gitbucket/gitbucket/releases/download/4.37.1/gitbucket.war
Create a dedicated directory for GitBucket and move the downloaded file:
sudo mkdir /opt/gitbucket
sudo mv gitbucket.war /opt/gitbucket
Step 4: Create a Systemd Service for GitBucket
To ensure that GitBucket starts automatically when your server reboots, create a systemd service file:
sudo nano /etc/systemd/system/gitbucket.service
Add the following content to the file:
[Unit]
Description=GitBucket Service
After=syslog.target
[Service]
ExecStart=/usr/bin/java -jar /opt/gitbucket/gitbucket.war
User=root
Restart=always
[Install]
WantedBy=multi-user.target
Save and close the file, then reload the systemd manager and start GitBucket:
sudo systemctl daemon-reload
sudo systemctl start gitbucket
sudo systemctl enable gitbucket
Step 5: Install Nginx
GitBucket runs on port 8080 by default, but it's a good practice to set up Nginx as a reverse proxy to serve GitBucket on port 80 (HTTP) or 443 (HTTPS). Install Nginx with the following command:
sudo apt install nginx -y
After installation, start and enable Nginx:
sudo systemctl start nginx
sudo systemctl enable nginx
Step 6: Configure Nginx as a Reverse Proxy for GitBucket
Next, create a new Nginx configuration file for GitBucket:
sudo nano /etc/nginx/sites-available/gitbucket
Add the following configuration, replacing your-domain.com
with your actual domain:
server {
listen 80;
server_name your-domain.com;
location / {
proxy_pass http://localhost: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;
}
}
Save and close the file, then enable the site and restart Nginx:
sudo ln -s /etc/nginx/sites-available/gitbucket /etc/nginx/sites-enabled/
sudo systemctl restart nginx
Step 7: Access GitBucket
Now, you can access GitBucket by visiting http://your-domain.com
or http://your-server-ip
in a web browser. The default login credentials are:
- Username:
root
- Password:
root
It is highly recommended to change the root password after your first login.
Step 8: (Optional) Enable SSL with Let's Encrypt
To secure your GitBucket instance with SSL, you can use Let's Encrypt. First, install Certbot:
sudo apt install certbot python3-certbot-nginx -y
Then, generate and install the SSL certificate by running the following command:
sudo certbot --nginx -d your-domain.com
Follow the prompts to complete the SSL installation. Certbot will automatically configure Nginx to redirect HTTP traffic to HTTPS.
Conclusion
By following these steps, you have successfully installed GitBucket with Nginx as a reverse proxy on Ubuntu 20.04 LTS. Whether you're hosting on a Windows VPS UK or other VPS solutions like Windows VPS Italy, GitBucket provides a flexible and powerful platform for managing Git repositories.