Installing Jenkins on Ubuntu

Skip to end of metadata
Go to start of metadata

On Debian-based distributions, such as Ubuntu, you can install Jenkins through apt-get.

Recent versions are available in an apt repository. Older but stable LTS versions are in this apt repository.

You need to have a JDK and JRE installed. openjdk-7-jre and openjdk-7-jdk are suggested. As of 2011-08 gcj is known to be problematic - see https://issues.jenkins-ci.org/browse/JENKINS-743.

Please make sure to back up any current Hudson or Jenkins files you may have.

Installation

wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt-get update
sudo apt-get install jenkins

Upgrade

Once installed like this, you can update to the later version of Jenkins (when it comes out) by running the following commands:

sudo apt-get update
sudo apt-get install jenkins

(aptitude or apt-get doesn't make any difference.)

What does this package do?

  • Jenkins will be launched as a daemon up on start. See /etc/init.d/jenkins for more details.
  • The 'jenkins' user is created to run this service.
  • Log file will be placed in /var/log/jenkins/jenkins.log. Check this file if you are troubleshooting Jenkins.
  • /etc/default/jenkins will capture configuration parameters for the launch like e.g JENKINS_HOME
  • By default, Jenkins listen on port 8080. Access this port with your browser to start configuration.
If your /etc/init.d/jenkins file fails to start jenkins, on line 108 you may change su -l <username> -c <command> with sudo -u <username> <command>. This fixed init.d script for me (icarito, July 2013).

Deploying on Ubuntu in a cloud (EC2, HP Cloud, OpenStack)

The Ubuntu Jenkins maintainer also maintains the Juju charm deployment/management script for deployment in clouds. It's designed to make it easy to deploy a master with multiple slaves:

juju deploy jenkins
juju deploy -n 5 jenkins-slave
juju add-relation jenkins jenkins-slave

The default password for the 'admin' account will be auto-generated. You can set it using:

juju set jenkins password=mypassword

Always change it this way - this account is used by the charm to manage slave configuration. Then feel free to expose your jenkins master:

juju expose jenkins

Setting up an Apache Proxy for port 80 -> 8080

  • This configuration will setup Apache2 to proxy port 80 to 8080 so that you can keep Jenkins on 8080.
  • sudo aptitude install apache2
  • sudo a2enmod proxy
  • sudo a2enmod proxy_http
do not do this next command if you already have virtual hosting setup that depends on the default site. See my comment below - danapsimer
  • sudo a2dissite default
  • Create a file called jenkins in /etc/apache2/sites-available
<VirtualHost *:80>
	ServerAdmin webmaster@localhost
	ServerName ci.company.com
	ServerAlias ci
	ProxyRequests Off
	<Proxy *>
		Order deny,allow
		Allow from all
	</Proxy>
	ProxyPreserveHost on
	ProxyPass / http://localhost:8080/
</VirtualHost>
  • sudo a2ensite jenkins
  • sudo apache2ctl restart

Setting up an Nginx Proxy for port 80 -> 8080

This configuration will setup Nginx to proxy port 80 to 8080 so that you can keep Jenkins on 8080. Instructions originally found in a GitHub Gist from rdegges: https://gist.github.com/913102

  • Install Nginx.
    sudo aptitude -y install nginx
    
  • Remove default configuration.
    cd /etc/nginx/sites-available
    sudo rm default ../sites-enabled/default
    
  • Create new configuration for Jenkins. This example uses cat, but you can use your favorite text editor. Make sure to replace 'ci.yourcompany.com' with your domain name.
    Note: Sometimes your permissions (umask, etc) might be setup such that this won't work. Create the file somewhere else then copy it into place if you run into that problem.
    sudo cat > jenkins
    upstream app_server {
        server 127.0.0.1:8080 fail_timeout=0;
    }
    
    server {
        listen 80;
        listen [::]:80 default ipv6only=on;
        server_name ci.yourcompany.com;
    
        location / {
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_redirect off;
    
            if (!-f $request_filename) {
                proxy_pass http://app_server;
                break;
            }
        }
    }
    ^D # Hit CTRL + D to finish writing the file
    
  • Link your configuration from sites-available to sites-enabled:
    sudo ln -s /etc/nginx/sites-available/jenkins /etc/nginx/sites-enabled/
    
  • Restart Nginx
    sudo service nginx restart
    

Where to go from here?

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Sep 15, 2009

    japher - says:

    The above instructions worked for me on Jaunty (9.04) Server, the daemon depende...

    The above instructions worked for me on Jaunty (9.04) Server, the daemon dependency was picked up correctly.

    There's a bug in the 1.322 and 1.323 releases of Hudson though that stops the hudson service starting up correctly. See https://hudson.dev.java.net/issues/show_bug.cgi?id=4304 (need to edit /etc/init.d/hudson and apply a fix as mentioned in the comments of that bug report).

  2. Sep 16, 2009

    benjamin dorsett says:

    On Jaunty (9.04) Server, the daemon dependency is picked up correctly. But Huds...

    On Jaunty (9.04) Server, the daemon dependency is picked up correctly.

    But Hudson doesn't start. Changing hudson user's shell to /bin/bash instead of /bin/false in /etc/passwd seems to fix it.

  3. Sep 18, 2009

    Jose Salvador says:

    My case: I work on a Debian Lenny dist (stable) I have updated the sources lis...

    My case:

    I work on a Debian Lenny dist (stable)

    I have updated the sources list following the instructions above and have applied the patch attached to the bug

    Then, I have had to install the sun-java6-bin package to get working. In my experience the hudson does not start with the debian gnu java. I obtained an exception related to this message:

    " Could not instantiate converter : com.thoughtworks.xstream.converters.extended.DurationConverter : null"

    Of course, I have changed the symbolic link at /usr/bin/java by one which links directly to the java from sun.

    Cheers.

  4. Sep 24, 2009

    Ben Standefer says:

    This fix worked for me when installing Hudson on Debian Lenny: "After installing...

    This fix worked for me when installing Hudson on Debian Lenny: "After installing the hudson deb on Ubuntu server Jaunty 8.10 [Debian Lenny in my case], when I tried to run the init script /etc/init.d/hudson start, nothing would be printed and the server would not start. No log file was created under /var/log/hudson and no pid file was created under /var/run/hudson. I eventually discovered that if i set the hudson user's shell to /bin/bash instead of /bin/false in /etc/passwd everything works fine. Hope this saves someone else some trouble."

    Also, this is a good resource: http://weblogs.java.net/blog/2008/06/11/debian-packages-hudson

  5. Apr 06, 2010

    Régis Desgroppes says:

    Hi, Hudson 1.353 was not published in the apt repository. Is there something wro...

    Hi,
    Hudson 1.353 was not published in the apt repository. Is there something wrong?
    Régis

  6. May 12, 2010

    Mohamed Ragab says:

    Hi, The latest version of Hudson as of the time of writing this comment is 1.35...

    Hi,

    The latest version of Hudson as of the time of writing this comment is 1.357 but the latest Debian package published is 1.352 and the latest RPM package published is 1.353

    Is this just lag, or is there a change in plans?

    Kind Regards
    Mohamed Ragab

  7. May 18, 2010

    Willem Verstraeten says:

    Hi, It seems as if the URL of the apt-get repository changed to deb http://jen...

    Hi,

    It seems as if the URL of the apt-get repository changed to
    deb http://jenkins-ci.org/debian binary/

    I did get an error on my Debian 5.0.4 machine, but on Ubuntu it seems to work. Got to investigate.

    The error was

    302 Found http://pkg.jenkins-ci.org/debian/binary/Packages

  8. May 23, 2010

    tcharl - says:

    Hi, Sorry, I can't find where I could post an Issue on Your JIRA. Can you put ...

    Hi,

    Sorry, I can't find where I could post an Issue on Your JIRA.

    Can you put the Latest 1.359 rpm's version please, we're stuck with 1.353 and so with the "java.lang.Error: This page expects a form submission" when creating a new Job

  9. Aug 28, 2010

    Max V.K. says:

    hi there. I've noticed the debian repository responds with response "302", which...

    hi there.
    I've noticed the debian repository responds with response "302", which is redirect related.
    apt does not support redirects as of now. Debian stabe apt does not.
    I am currently forced to download the file manually, although it is found in the repository.

    Can somebody please change the setup so that not a redirect is returned, but the file?

    Thanks.

  10. Nov 08, 2010

    Stefan Seidel says:

    Here's a workaround for lenny: you need: apache2, mod_proxy. Then create a file...

    Here's a workaround for lenny: you need: apache2, mod_proxy.

    Then create a file /etc/apache2/sites-available/hudson-deb with this content:

    <VirtualHost *:80>
      ServerName hudson-deb.local
      RewriteEngine On
      RewriteRule ^/debian/binary/(.+\.deb) http://download.jenkins-ci.org/debian/$1 [P]
      RewriteRule ^(.*)$ http://pkg.jenkins-ci.org$1 [P]
      <Proxy *>
        Order Deny,Allow
        Allow from all
      </Proxy>
    </VirtualHost>
    

    Edit /etc/hosts and add hudson-deb.local as the last term on the line containing 127.0.0.1 (separate it with a space).

    Then enable the proxy and the site and restart the apache:

    a2enmod proxy_http
    a2ensite hudson-deb
    /etc/init.d/apache2 restart
    

    Then you just add the file /etc/apt/sources.list.d/hudson.list with the following content:

    deb http://hudson-deb.local/debian binary/
    

    And off you go with:

    apt-get update && apt-get install hudson
    
  11. Apr 12, 2011

    Dana P'Simer says:

    the "sudo a2dissite default" step should only be done if you do not want the def...

    the "sudo a2dissite default" step should only be done if you do not want the default site to stay in place.  All the steps described should work without this step in a normal virtual hosted environment on a Debian/Ubuntu installation.

  12. Jul 22, 2011

    Steven Bromley says:

    It should probably be more clear that installing Jenkins is going to replace any...

    It should probably be more clear that installing Jenkins is going to replace any current installations of Hudson you have on a box.

  13. Oct 10, 2011

    Barry Warsaw says:

    Ubuntu 11.10 (Oneiric) has Jenkins 1.409.1 afaict.   sudo apt-get install j...

    Ubuntu 11.10 (Oneiric) has Jenkins 1.409.1 afaict.   sudo apt-get install jenkins jenkins-cli should get you the basics (do aptitude search jenkins for the full suite of packages).  sudo service jenkins start should start the server by default on localhost:8080.

  14. Nov 23, 2011

    Ed Young says:

    I have jenkins conflicting with tomcat because both run on port 8080. I've just...

    I have jenkins conflicting with tomcat because both run on port 8080.

    I've just upgraded to 11.10 and installed tomcat7 (port 8080 default) and then jenkins as a standalone. Both done using synaptic.

    jenkins fails with a port already in use exception, so I need to reconfigure it so it's on a different port. What's the best way to do this?

    The section above entitled:

    Setting up an Apache Proxy for port 80 -> 8080

    • This configuration will setup Apache2 to proxy port 80 to 8080 so that you can keep Jenkins on 8080.

    If I follow that, it appears that jenkins will still be on port 8080, and that will conflict with tomcat.

    I'm only starting to be familiar with how Ubuntu installs tomcat and jenkins. What's the best way to change the port of either tomcat or jenkins from 8080 so they don't conflict?

  15. Nov 23, 2011

    Ed Young says:

    Where can I find the configuration file to change the port where jenkins runs? ...

    Where can I find the configuration file to change the port where jenkins runs?

    the instructions above indicate that

    /etc/default/jenkins will capture configuration parameters for the launch.

    After installation using synaptic on 11.10, there is no /etc/default/jenkins file.

    1. Apr 18, 2012

      Benny Chew says:

      Just installed using Aptitude (v1.460) on Ubuntu 11.10, the line in /etc/default...

      Just installed using Aptitude (v1.460) on Ubuntu 11.10, the line in /etc/default/jenkins to change would be the following:

      # port for HTTP connector (default 8080; disable with -1)
      HTTP_PORT=8080
      
  16. Oct 02, 2012

    Chin Fang says:

    Why in the current Ubuntu package, 1.484, the group for the 'jenkins' user is se...

    Why in the current Ubuntu package, 1.484, the group for the 'jenkins' user is set to 'nogroup'?  The group in the corresponding RPM is set to 'jenkins' however. Admitted this is not a fatal inconsistency, but an inconsistency nevertheless?

  17. Oct 01, 2013

    Anton Trapp says:

    On debian squeeze one of the latest updates does something very ugly... - runnin...

    On debian squeeze one of the latest updates does something very ugly... - running system - aptitude update - now this:

    org.jvnet.hudson.reactor.ReactorException: hudson.util.IOException2: Unable to read /var/lib/jenkins/config.xml	at org.jvnet.hudson.reactor.Reactor.execute(Reactor.java:246)
    at jenkins.InitReactorRunner.run(InitReactorRunner.java:43)
    at jenkins.model.Jenkins.executeReactor(Jenkins.java:910)
    at jenkins.model.Jenkins.<init>(Jenkins.java:806)
    at hudson.model.Hudson.<init>(Hudson.java:81)
    at hudson.model.Hudson.<init>(Hudson.java:77)
    at hudson.WebAppMain$3.run(WebAppMain.java:221)
    Caused by: hudson.util.IOException2: Unable to read /var/lib/jenkins/config.xml
    at hudson.XmlFile.unmarshal(XmlFile.java:170)
    at jenkins.model.Jenkins$17.run(Jenkins.java:2530)
    at org.jvnet.hudson.reactor.TaskGraphBuilder$TaskImpl.run(TaskGraphBuilder.java:146)
    at org.jvnet.hudson.reactor.Reactor.runTask(Reactor.java:259)
    at jenkins.model.Jenkins$7.runTask(Jenkins.java:899)
    at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:187)
    at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:94)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:679)
    Caused by: com.thoughtworks.xstream.converters.ConversionException: Could not set field class hudson.security.csrf.DefaultCrumbIssuer.PROXY_HEADER : null : Could not set field class hudson.security.csrf.DefaultCrumbIssuer.PROXY_HEADER : null
    ---- Debugging information ----
    message : Could not set field class hudson.security.csrf.DefaultCrumbIssuer.PROXY_HEADER : null
    cause-exception : com.thoughtworks.xstream.converters.reflection.ObjectAccessException
    cause-message : Could not set field class hudson.security.csrf.DefaultCrumbIssuer.PROXY_HEADER : null
    class : hudson.security.csrf.DefaultCrumbIssuer
    required-type : hudson.security.csrf.DefaultCrumbIssuer
    converter-type : hudson.util.RobustReflectionConverter
    path : /hudson/crumbIssuer/PROXY_HEADER
    line number : 65
    class1 : hudson.model.Hudson
    version : not available
    
    <?xml version='1.0' encoding='UTF-8'?>
    <hudson>
    <disabledAdministrativeMonitors/>
    <version>1.521</version>
    <numExecutors>1</numExecutors>
    <mode>NORMAL</mode>
    <useSecurity>true</useSecurity>
    <authorizationStrategy class="hudson.security.ProjectMatrixAuthorizationStrategy">
    <permission>hudson.model.Computer.Build:atrapp</permission>
    <permission>hudson.model.Computer.Configure:atrapp</permission>
    <permission>hudson.model.Computer.Connect:atrapp</permission>
    <permission>hudson.model.Computer.Create:atrapp</permission>
    <permission>hudson.model.Computer.Delete:atrapp</permission>
    <permission>hudson.model.Computer.Disconnect:atrapp</permission>
    <permission>hudson.model.Hudson.Administer:atrapp</permission>
    <permission>hudson.model.Hudson.ConfigureUpdateCenter:atrapp</permission>
    <permission>hudson.model.Hudson.Read:atrapp</permission>
    <permission>hudson.model.Hudson.RunScripts:atrapp</permission>
    <permission>hudson.model.Hudson.UploadPlugins:atrapp</permission>
    <permission>hudson.model.Item.Build:atrapp</permission>
    <permission>hudson.model.Item.Cancel:atrapp</permission>
    <permission>hudson.model.Item.Configure:atrapp</permission>
    <permission>hudson.model.Item.Create:atrapp</permission>
    <permission>hudson.model.Item.Delete:atrapp</permission>
    <permission>hudson.model.Item.Discover:atrapp</permission>
    <permission>hudson.model.Item.Read:atrapp</permission>
    <permission>hudson.model.Item.Workspace:atrapp</permission>
    <permission>hudson.model.View.Configure:atrapp</permission>
    <permission>hudson.model.View.Create:atrapp</permission>
    <permission>hudson.model.View.Delete:atrapp</permission>
    <permission>hudson.model.View.Read:atrapp</permission>
    </authorizationStrategy>
    <securityRealm class="hudson.security.HudsonPrivateSecurityRealm">
    <disableSignup>false</disableSignup>
    <enableCaptcha>false</enableCaptcha>
    </securityRealm>
    <projectNamingStrategy class="jenkins.model.ProjectNamingStrategy$DefaultProjectNamingStrategy"/>
    <workspaceDir>$
    
    {JENKINS_HOME}
    /workspace/$
    
    {ITEM_FULLNAME}
    </workspaceDir>
    <buildsDir>$
    
    {ITEM_ROOTDIR}
    /builds</buildsDir>
    <systemMessage>bla bla not relevant here</systemMessage>
    <markupFormatter class="hudson.markup.RawHtmlMarkupFormatter">
    <disableSyntaxHighlighting>false</disableSyntaxHighlighting>
    </markupFormatter>
    <jdks/>
    <viewsTabBar class="hudson.views.DefaultViewsTabBar"/>
    <myViewsTabBar class="hudson.views.DefaultMyViewsTabBar"/>
    <clouds/>
    <slaves/>
    <quietPeriod>60</quietPeriod>
    <scmCheckoutRetryCount>0</scmCheckoutRetryCount>
    <views>
    <hudson.model.AllView>
    <owner class="hudson" reference="../../.."/>
    <name>Alle</name>
    <filterExecutors>false</filterExecutors>
    <filterQueue>false</filterQueue>
    <properties class="hudson.model.View$PropertyList"/>
    </hudson.model.AllView>
    </views>
    <primaryView>Alle</primaryView>
    <slaveAgentPort>0</slaveAgentPort>
    <label></label>
    <crumbIssuer class="hudson.security.csrf.DefaultCrumbIssuer">
    <excludeClientIPFromCrumb>false</excludeClientIPFromCrumb>
    <PROXY_HEADER>X-Forwarded-For</PROXY_HEADER>
    </crumbIssuer>
    <nodeProperties/>
    <globalNodeProperties/>
    </hudson>
    
  18. Nov 15, 2013

    Dmitry Sheiko says:

    On dpkg-deb: error: subprocess paste was killed by signal (Broken pipe) Errors w...

    On dpkg-deb: error: subprocess paste was killed by signal (Broken pipe)
    Errors were encountered while processing:
     /var/cache/apt/archives/jenkins_1.539_all.deb
    E: Sub-process /usr/bin/dpkg returned an error code (1)
    On Ubuntu 12.04.3 LTS on any attempt to install jenkins
    sudo apt-get install jenkins
    sudo apt-get install -f jenkins

    it ends up with the error:

    ...

    dpkg: error processing /var/cache/apt/archives/jenkins_1.539_all.deb (--unpack):

     trying to overwrite '/usr/share/jenkins/jenkins.war', which is also in package jenkins-common 1.424.6+dfsg-1ubuntu0.2

    dpkg-deb: error: subprocess paste was killed by signal (Broken pipe)

    Errors were encountered while processing:

     /var/cache/apt/archives/jenkins_1.539_all.deb

    E: Sub-process /usr/bin/dpkg returned an error code (1)

    P.S. I tried to install some  old version
    apt-get install jenkins=1.424.6+dfsg-1ubuntu0.2
    and it worked fine

  19. Apr 08

    Michael Kryzhanovsky says:

    Installing under apache has some caveats. In my case I wanted Jenkins to respond...

    Installing under apache has some caveats. In my case I wanted Jenkins to respond to a subomain, e.g. ci.myhost.com. In this case the config should be as follows:

    <VirtualHost *:80>
            ServerName ci.myhost.com
            ServerAlias ci
    
            ProxyRequests Off
            <Proxy *>
                    Order deny,allow
                    Allow from all
            </Proxy>
            ProxyPreserveHost on
            ProxyPass / http://localhost:8080/ nocanon
            ProxyPassReverse / http://ci.myhost.com/
            AllowEncodedSlashes NoDecode
    </VirtualHost>

    Note, that nocanon and NoDecode are important.
    A simple tool comes with Jenkins to test your proxy configuration, so you can check if everything works correctly as follows:
    curl -iL http://ci.myhost.com/administrativeMonitor/hudson.diagnosis.ReverseProxySetupMonitor/test