View Source

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

Recent versions are available in [an apt repository|http://jenkins-ci.org/debian/]. Older but stable LTS versions are in [this apt repository|http://pkg.jenkins-ci.org/debian-stable/].

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|https://issues.jenkins-ci.org/browse/JENKINS-743].

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

h1. Installation

{noformat}
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
{noformat}

h1. Upgrade

Once installed like this, you can update to the later version of Jenkins (when it comes out) by running the following commands:
{noformat}
sudo apt-get update
sudo apt-get install jenkins
{noformat}
(aptitude or apt-get doesn't make any difference.)

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


{note}
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).
{note}

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

The Ubuntu Jenkins maintainer also maintains the [Juju charm deployment/management script|http://jujucharms.com/charms/precise/jenkins] for deployment in clouds. It's designed to make it easy to deploy a master with multiple slaves:
{noformat}
juju deploy jenkins
juju deploy -n 5 jenkins-slave
juju add-relation jenkins jenkins-slave
{noformat}

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

{noformat}
juju set jenkins password=mypassword
{noformat}

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

h1. 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}}

{note}do not do this next command if you already have virtual hosting setup that depends on the default site. See my comment below - danapsimer{note}
* {{sudo a2dissite default}}
* {{Create a file called}} {{{+}jenkins{+}}} {{in}} /etc/apache2/sites-available

{code:xml}
<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>
{code}

* {{sudo a2ensite jenkins}}
* {{sudo apache2ctl restart}}

h1. 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://github.com/rdegges]: [https://gist.github.com/913102]




* *Install Nginx*.
{code}
sudo aptitude -y install nginx
{code}
* *Remove default configuration*.
{code}
cd /etc/nginx/sites-available
sudo rm default ../sites-enabled/default
{code}
* *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.
{code}
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
{code}

* *Link your configuration* from {{sites-available}} to {{sites-enabled}}:
{code}
sudo ln -s /etc/nginx/sites-available/jenkins /etc/nginx/sites-enabled/
{code}
* *Restart Nginx*
{code}
sudo service nginx restart
{code}


h1. Where to go from here?

* You might want to [make Jenkins visible through Apache|Running Jenkins behind Apache], to make it available on port 80 (for example, [http://myserver/jenkins/] instead of [http://myserver:8080/]). See [this blog for more details|http://www.zzorn.net/2009/11/setting-up-hudson-on-port-80-on-debian.html]