Child pages
  • Installing Jenkins on Ubuntu
Skip to end of metadata
Go to start of metadata

Out of date

This content is out of date. See the Ubuntu installation section of the handbook on jenkins.io for Debian and Ubuntu installation instructions

 

 

 

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 - https://pkg.jenkins.io/debian/jenkins-ci.org.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable 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, edit the /etc/default/jenkins to replace the line

HTTP_PORT=8080

by

HTTP_PORT=8081

Here, 8081 was chosen but you can put another port available.

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

Using Linux iptables for port 80 -> 8080

  • This enables port forwarding of traffic between ports 80 and 8080. You can keep Jenkins on the default port 8080 and access it with a normal url without installing anything extra.
  • sudo nano /etc/rc.local
  • Then add the following just before the exit 0
#Requests from outside
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8080
#Requests from localhost
iptables -t nat -I OUTPUT -p tcp -d 127.0.0.1 --dport 80 -j REDIRECT --to-ports 8080

Now reboot or run sudo /etc/rc.local to enable port forwarding. Additional info: https://gist.github.com/m5m1th/6870a54717c0387468c3

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

If you get ERROR: Site default does not exist! then try this instead:

  • sudo a2dissite 000-default

And if all else fails just have a look if there is a default site set up at all:

  • ls /etc/apache2/sites-enabled/
  • Create a file called jenkins.conf 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/ nocanon
	AllowEncodedSlashes NoDecode
</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?

25 Comments

  1. 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. 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. Unknown User (joansava@gmail.com)

    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. Unknown User (aguynamedben)

    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. Hi,
    Hudson 1.353 was not published in the apt repository. Is there something wrong?
    Régis

  6. Unknown User (moragab@gmail.com)

    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. 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. 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. Unknown User (sobersabre)

    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. 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. 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. It should probably be more clear that installing Jenkins is going to replace any current installations of Hudson you have on a box.

  13. 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. 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. 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. 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. 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. 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. 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. 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

  20. Above didn't work for me unfortunately.  Ubuntu 14.04, followed the instructions down to apt-get install.  I changed the port number to 8888.  ps shows that jenkins is running:

    /usr/bin/java -Djava.awt.headless=true -jar /usr/share/jenkins/jenkins.war --webroot=/var/cache/jenkins/war --httpPort=8888 --ajp13Port=-1

    but there is no response when I try to connect to port 8888.  The log looks clean except for the "NO JSP support" message:

    Running from: /usr/share/jenkins/jenkins.war
    Mar 10, 2015 5:07:55 PM winstone.Logger logInternal
    INFO: Beginning extraction from war file
    Mar 10, 2015 5:07:55 PM org.eclipse.jetty.util.log.JavaUtilLog info
    INFO: jetty-winstone-2.8
    Mar 10, 2015 5:07:57 PM org.eclipse.jetty.util.log.JavaUtilLog info
    INFO: NO JSP Support for , did not find org.apache.jasper.servlet.JspServlet
    Jenkins home directory: /var/lib/jenkins found at: EnvVars.masterEnvVars.get("JENKINS_HOME")
    Mar 10, 2015 5:07:58 PM org.eclipse.jetty.util.log.JavaUtilLog info
    INFO: Started SelectChannelConnector@0.0.0.0:8888
    Mar 10, 2015 5:07:58 PM winstone.Logger logInternal
    INFO: Winstone Servlet Engine v2.0 running: controlPort=disabled

    ...

    When my browser tries to connect to port 8888, wireshark shows an HTTP GET being sent, and that is all.

    Where do I go from here?

  21. With newer Ubuntu 15.04 where 'sh' resolves to 'dash' instead of 'bash' I had to use this command:

    sudo bash -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list'
    
  22. Hi,

    Can anyone tell me what is the minimum java version required for Jenkins 2.x version.

    Do we need to update java to 1.8 or 1.7 will be fine. I installed it on debian 7 with java 1.7 and jenkins service is not starting.

    Thanks,

  23. Hi ,

    sudo apt-get update 

    After this getting below error .

    Err:6 http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 Release.gpg                                
      The following signatures were invalid: KEYEXPIRED 1507497109
    Hit:10 http://gb.archive.ubuntu.com/ubuntu xenial InRelease                           
    Get:11 http://gb.archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]        
    Ign:12 http://pkg.jenkins.io/debian-stable binary/ InRelease                        
    Hit:13 http://pkg.jenkins.io/debian-stable binary/ Release               
    Get:14 http://gb.archive.ubuntu.com/ubuntu xenial-backports InRelease [102 kB]
    Ign:16 https://dl.bintray.com/pcp/xenial xenial InRelease     
    Get:17 https://dl.bintray.com/pcp/xenial xenial Release [1,840 B]
    Hit:17 https://dl.bintray.com/pcp/xenial xenial Release
    Fetched 311 kB in 2s (141 kB/s)
    Reading package lists... Done
    W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 Release: The following signatures were invalid: KEYEXPIRED 1507497109
    W: Failed to fetch http://repo.mongodb.org/apt/ubuntu/dists/xenial/mongodb-org/3.2/Release.gpg  The following signatures were invalid: KEYEXPIRED 1507497109
    W: Some index files failed to download. They have been ignored, or old ones used instead.

    Thanks

    Kalyan Sarkar

Write a comment…