Linux Mint 18.3下Jenkins主目录修改无效问题求助
Hey there! Let's break down why your attempt to change JENKINS_HOME via the .profile file didn't work, and how to fix it properly.
The Root Cause
Jenkins runs as a system service on most Linux distros (including Mint 18.3), not as a regular user process. System services don't load user-specific shell configuration files like .profile—those only get read when you log into an interactive shell (e.g., opening a terminal or SSHing in). So your export line in .profile never gets picked up by the Jenkins service.
Step 1: Verify Jenkins' Startup Method
First, check if Jenkins uses systemd or upstart (Mint 18.3 is based on Ubuntu 16.04, which defaults to upstart, but some setups might use systemd):
- Run
systemctl status jenkins—if it shows "active (running)", you're using systemd. - If that returns an error, run
sudo service jenkins status—if it works, you're using upstart.
Step 2: Update the Service Configuration
Choose the section below that matches your startup method:
Option A: For Systemd
- Stop Jenkins first:
sudo systemctl stop jenkins - Create an override file (safer than editing the main service file directly):
sudo systemctl edit jenkins - In the text editor that opens, paste this content:
[Service] Environment="JENKINS_HOME=/home/alex/JenkinsHome/" - Save and exit the editor.
- Reload systemd to apply the changes:
sudo systemctl daemon-reload - Start Jenkins back up:
sudo systemctl start jenkins
Option B: For Upstart
- Stop Jenkins:
sudo service jenkins stop - Edit the upstart configuration file:
sudo nano /etc/init/jenkins.conf - Look for a line starting with
env JENKINS_HOME=. If you find it, replace the path with/home/alex/JenkinsHome/. If not, add this line near the top of the file:env JENKINS_HOME=/home/alex/JenkinsHome/ - Save the file (Ctrl+O, then Enter) and exit nano (Ctrl+X).
- Start Jenkins again:
sudo service jenkins start
Step 3: Fix Directory Permissions
Jenkins runs under the jenkins system user, so your new home directory needs the right permissions for it to read/write data:
sudo chown -R jenkins:jenkins /home/alex/JenkinsHome/ sudo chmod -R 755 /home/alex/JenkinsHome/
Step 4: Verify the Change
To confirm Jenkins is using the new home directory:
- Check the Jenkins logs:
- For systemd:
journalctl -u jenkins | grep JENKINS_HOME - For upstart:
cat /var/log/jenkins/jenkins.log | grep JENKINS_HOME
- For systemd:
- Or inspect the process environment variables:
cat /proc/$(pgrep jenkins)/environ | tr '\0' '\n' | grep JENKINS_HOME
Quick Note on Your Initial Copy
Make sure you copied the original Jenkins data with permissions preserved. If you used a regular cp command, re-copy it with:
sudo cp -a /var/lib/jenkins/* /home/alex/JenkinsHome/
The -a flag preserves ownership, permissions, and symbolic links—critical for Jenkins to work correctly with the copied data.
内容的提问来源于stack exchange,提问作者OleksandrP

