<p>This question was already <a href="https://stackoverflow.com/questions/13192322/how-to-change-home-directory-of-jenkins">asked and answered</a> on Stack Overflow.  I'll copy the top answer here, but there are several other answers over there that you may find useful:</p>
<blockquote>
<p>For me on Jenkins 2.7.2 on RHEL 7.2 after already starting jenkins and
configuring a build, I needed to:</p>
<ol>
<li><p>Change the jenkins user's home directory</p>
<pre><code>sudo su -
service jenkins stop
vi /etc/passwd
#  change the /var/lib/jenkins to /home/jenkins or whatever 
</code></pre>
</li>
<li><p>Change the setting in the start script to also find it</p>
<pre><code>vi /etc/sysconfig/jenkins
#   change the JENKINS_HOME to /home/jenkins or what ever
</code></pre>
</li>
<li><p>Copy all the data to the new location (eg: /home/jenkins)</p>
<pre><code>cd /home
cp -Rf /var/lib/jenkins .
chown -R jenkins:jenkins *
</code></pre>
</li>
<li><p>Start it back up</p>
<pre><code>service jenkins start
</code></pre>
</li>
</ol>
<p>And that seems to have done it for me.</p>
</blockquote>

CC BY-SA 4.0
2022-04-14T19:44:02.600Z
2022-04-14T19:44:02.600Z
jayhendren
<p>I was having the same problem on a Centos 7.9 system using Jenkins 2.346.2</p>
<p>Sometime around 2.332.1 Jenkins migrated from init.d to system.d, so the previous method of updating the /etc/sysconfig/jenkins (or /etc/default/jenkins) became deprecated.</p>
<p>You now use overrides through:  systemctl edit jenkins</p>
<p>Jenkins systemd reference:
<a href="https://www.jenkins.io/doc/book/system-administration/systemd-services/" rel="nofollow noreferrer">https://www.jenkins.io/doc/book/system-administration/systemd-services/</a></p>

CC BY-SA 4.0
2022-07-20T21:11:12.280Z
2022-07-20T21:11:12.280Z
Jim Abrille
<p>The following script can be used to do what you want:</p>
<pre class="lang-bash prettyprint-override"><code># become root
sudo -i

# stop the jenkins service
systemctl stop jenkins

# create the directory where you want jenkins
mkdir -p /[path to your jenkins instance]

vi /etc/sysconfig/jenkins
# change JENKINS_HOME to /[path to your jenkins instance]

vi /etc/passwd
#  change the default /var/lib/jenkins to /[path to your jenkins instance]

mv -R /var/lib/jenkins /[path to your jenkins instance]

# grant ownership of all the files to jenkins
chown -R jenkins:jenkins .[path to your jenkins instance]

# start jenkins
systemctl start jenkins 

# if you want jenkins to start upon every reboot
systemctl enable jenkins
</code></pre>

CC BY-SA 4.0
2022-04-15T06:03:41.797Z
2022-04-15T07:13:43.840Z
2022-04-15T07:13:43.840Z
Max Haase
<p>In the Jenkins web interface, under <em>Home directory</em> (Dashboard -&gt; Mange Jenkins -&gt; Configure System), the help section says the following:</p>
<ul>
<li>&quot;By default, Jenkins stores all of its data in this directory on the
file system&quot;, referring to /var/lib/jenkins</li>
<li>&quot;Edit the JENKINS_HOME variable in your Jenkins configuration file (e.g. /etc/sysconfig/jenkins on Red Hat Linux)&quot;</li>
</ul>
<p>However, my etc directory doesn't have a directory called sysconfig.</p>
<p>Running the following command returns a lot of files among which only the following seems relevant:</p>
<pre><code>find ~/ -type f -name &quot;config.xml&quot;
&lt;...&gt;
/var/lib/jenkins/config.xml
&lt;...&gt;
</code></pre>
<p>The file contains the following field:</p>
<pre><code>&lt;workspaceDir&gt;${JENKINS_HOME}/workspace/${ITEM_FULL_NAME}&lt;/workspaceDir&gt;
</code></pre>
<p>Is this the correct field to edit? If so, which syntax should I follow while entering the desired path?</p>

<jenkins><configuration><ubuntu>
In Ubuntu, how do I change the home path of Jenkins using the CLI?
Omar Shazly
# In Ubuntu, how do I change the home path of Jenkins using the CLI?

(Asked by: username_0 on 2022-04-13)

In the Jenkins web interface, under Home directory (Dashboard -> Mange Jenkins -> Configure System), the help section says the following:

"By default, Jenkins stores all of its data in this directory on the
file system", referring to /var/lib/jenkins
"Edit the JENKINS_HOME variable in your Jenkins configuration file (e.g. /etc/sysconfig/jenkins on Red Hat Linux)"

However, my etc directory doesn't have a directory called sysconfig.
Running the following command returns a lot of files among which only the following seems relevant:
find ~/ -type f -name "config.xml"
<...>
/var/lib/jenkins/config.xml
<...>

The file contains the following field:
${JENKINS_HOME}/workspace/${ITEM_FULL_NAME}

Is this the correct field to edit? If so, which syntax should I follow while entering the desired path?

**Tags:** jenkins, configuration, ubuntu


---

## 3 answers

### Answer by username_1 on 2022-04-14. Score: 1

This question was already asked and answered on Stack Overflow.  I'll copy the top answer here, but there are several other answers over there that you may find useful:

For me on Jenkins 2.7.2 on RHEL 7.2 after already starting jenkins and
configuring a build, I needed to:

Change the jenkins user's home directory
sudo su -
service jenkins stop
vi /etc/passwd
#  change the /var/lib/jenkins to /home/jenkins or whatever 


Change the setting in the start script to also find it
vi /etc/sysconfig/jenkins
#   change the JENKINS_HOME to /home/jenkins or what ever


Copy all the data to the new location (eg: /home/jenkins)
cd /home
cp -Rf /var/lib/jenkins .
chown -R jenkins:jenkins *


Start it back up
service jenkins start



And that seems to have done it for me.


---

### Answer by username_2 on 2022-07-20. Score: 1

I was having the same problem on a Centos 7.9 system using Jenkins 2.346.2

Sometime around 2.332.1 Jenkins migrated from init.d to system.d, so the previous method of updating the /etc/sysconfig/jenkins (or /etc/default/jenkins) became deprecated.

You now use overrides through: systemctl edit jenkins

Jenkins systemd reference:
<https://www.jenkins.io/doc/book/system-administration/systemd-services/>


---

### Answer by username_3 on 2022-04-15. Score: 0

The following script can be used to do what you want:
# become root
sudo -i

# stop the jenkins service
systemctl stop jenkins

# create the directory where you want jenkins
mkdir -p /[path to your jenkins instance]

vi /etc/sysconfig/jenkins
# change JENKINS_HOME to /[path to your jenkins instance]

vi /etc/passwd
#  change the default /var/lib/jenkins to /[path to your jenkins instance]

mv -R /var/lib/jenkins /[path to your jenkins instance]

# grant ownership of all the files to jenkins
chown -R jenkins:jenkins .[path to your jenkins instance]

# start jenkins
systemctl start jenkins 

# if you want jenkins to start upon every reboot
systemctl enable jenkins


---

