Você está na página 1de 6

Install GitLab on Ubuntu 14.

04 (Trusty Tahr)

https://www.linode.com/docs/applications/deve...

Guides & Tutorials (/docs/)


Applications (/docs/applications/)
Development (/docs/applications/development/)
Install GitLab on Ubuntu 14.04 (Trusty Tahr)
Search guides...

Install GitLab on Ubuntu


14.04 (Trusty Tahr)

In This Guide:

Updated Thursday, September 4th, 2014 by Alex Fornuto

System
Requirements

Contribute on GitHub

Contributed by Nashruddin Amin (https://twitter.com/bsd_noobz)

Prepare System
for Deployment
Install Package
Dependencies

View Project (https://github.com/linode/docs) | View File (https://github.com/linode/docs/blob


/master/docs/applications/development/install-gitlab-on-ubuntu-14-04-trusty-tahr.md) | Edit
File (https://github.com/linode/docs/edit/master/docs/applications/development/install-gitlabon-ubuntu-14-04-trusty-tahr.md)

Install Ruby
Setup PostgreSQL
Database for
GitLab

This is a Linode Community guide. Write for us (/docs


/contribute) and earn $250 per published guide.

Install GitLab
Set Up Nginx
Virtual Host for
GitLab
Open GitLab on
Your Browser
Securing GitLab
RSS feed
(https://www.linode.com
/docs/rss)

Try this guide on a


Linode!
Use promo code
DOCS10 for $10
credit on a new
account.

GitLab is a free git repository management application based


on Ruby on Rails. It is an interesting alternative if you want to
host your own git repositories, since third-party hosting is not
always the best option when writing private or closed-source
software.
GitLab provides a .deb package (https://www.gitlab.com
/downloads/) which contains GitLab Community Edition and
all its dependencies (Ruby, PostgreSQL, Redis, Nginx,
Unicorn and other gems) already compiled. Installing this
package is straightforward (https://gitlab.com/gitlaborg/omnibus-gitlab/blob/master/README.md#installation).
But since it will install its own package dependencies (Nginx,
PostgreSQL, etc), this installation method is suitable if the
server is dedicated only to managing git repositories. If you
want GitLab to use your existing resources (i.e: you already
have Nginx and PostgreSQL installed), you need to install
GitLab manually.

Create Account (hps://manager.linode.com/session/signup)

Monthly Guides
Update
Email address

Sign Up

This guide will help you install and configure GitLab on your
Ubuntu 14.04 (Trusty Tahr) Linode. We will be using the
latest Ruby and GitLab as of this writing, so check for the
latest version. We will assume that you want to install GitLab
on git.example.com and you have configured the DNS
properly. If you are new to Linux system administration, you
might want to consider the Introduction to Linux Concepts
guide (/docs/tools-reference/introduction-to-linux-concepts)
and Linux Administration Basics guide (/docs/tools-reference
/linux-system-administration-basics) guides.
Note
This guide is written for non-root users. Commands that require
elevated privileges are prefixed with sudo. If you are not familiar with
the sudo command, you can check out our Users and Groups (/docs
/tools-reference/linux-users-and-groups) guide.

System Requirements
GitLab is a large and heavy application. To get the most of
GitLab, the recommended hardware is as follows:
CPU: 2 cores to support up to 500 users.
Memory: 2 GB to support up to 500 users.

Prepare System for Deployment


Before beginning with the GitLab installation, make sure that
your systems package database is up to date and that all
installed software is running the latest version.
1. Update your system by issuing the following commands
from your shell:
1
2

sudo apt-get update


sudo apt-get upgrade

2. Also create a git user for GitLab:


1

sudo adduser --disabled-login --gecos 'GitLab' git

Install Package Dependencies


In this section you will install the development tools and the
required packages for GitLab.
1. Install the required packages to compile Ruby and native
extensions to Ruby gems:

1 de 6

13-05-2016 15:24

Install GitLab on Ubuntu 14.04 (Trusty Tahr)

https://www.linode.com/docs/applications/deve...

sudo apt-get install build-essential cmake zlib1g-dev libyaml-dev

2. Install Git:
1

sudo apt-get install git

3. In order to receive mail notifications, you need to install a


mail server. Issue the following command to install
Postfix mail server:
1

sudo apt-get install postfix

Select Internet site and enter your hostname to


complete the installation. If you need to set up a
complete SMTP/IMAP/POP3 server, refer to the Email
with Postfix, Dovecot, and MySQL (/docs/email/postfix
/email-with-postfix-dovecot-and-mysql) guide.

Install Ruby
While GitLab is a Ruby on Rails application, using ruby
version managers such as RVM (http://rvm.io/) and rbenv
(https://github.com/sstephenson/rbenv) is not supported. For
example, GitLab shell is called from OpenSSH and having a
version manager can prevent pushing and pulling over SSH.
Thus GitLab can only work with system-wide Ruby
installation. In addition, GitLab requires Ruby 2.0 or higher
while the default version on Ubuntu 14.04 is 1.9.3.
1. Remove the old Ruby if present:
1

sudo apt-get remove ruby

2. The current stable Ruby version as of this writing is


2.1.2. To install Ruby, download the source code and
compile the package:
1
2
3
4
5
6
7

mkdir /tmp/ruby && cd /tmp/ruby


wget http://ftp.ruby-lang.org/pub/ruby/2.1/ruby-2.1.2.tar.gz
tar xvzf ruby-2.1.2.tar.gz
cd ruby-2.1.2
./configure --disable-install-rdoc --prefix=/usr/local
make
sudo make install

3. Check if the installation succeed by checking the Ruby


version:
1

ruby -v

Setup PostgreSQL Database for


GitLab
GitLab supports both MySQL and PostgreSQL for the
database backend, but the latter is recommended. GitLab
requires PostgreSQL version 9.1 or higher since it needs to
make use of extensions.
1. Install PostgreSQL if you havent installed it:
1

sudo apt-get install postgresql postgresql-client libpq-dev

2. Create new database and new user by issuing the


following commands:
1
2

sudo -u postgres createuser --createdb git


sudo -u postgres createdb --owner=git gitlabhq_production

3. Try connecting to the new database with the new user


and display PostgreSQL version for testing:
1

sudo -u git -H psql -d gitlabhq_production -c "SELECT VERSION()"

If everything is ok, you should see the PostgreSQL


version displayed on the console like this:
1
2
3
4

version
-----------------------------------------------------------------PostgreSQL 9.3.4 on x86_64-unknown-linux-gnu, compiled by gcc (Ub
(1 row)

Install GitLab
In this section you will install GitLab and make some
configuration changes.
1. We will install GitLab into home directory of the user git.
Change the current working directory:
1

2 de 6

cd /home/git

13-05-2016 15:24

Install GitLab on Ubuntu 14.04 (Trusty Tahr)

https://www.linode.com/docs/applications/deve...

2. Download the GitLab source:


1
2

sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.g


cd gitlab

The command above will download the 6-9-stable branch


from the GitLab repository. Feel free to select other
stable branches, but never install the master branch on a
production server.
3. Create the GitLab config file:
1

sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml

Open the file:


1

sudo nano config/gitlab.yml

You need to change the value of host to the fullyqualified domain of your server. Also set the email_from
and support_email to the email addresses intended for
GitLab.
File excerpt: /home/git/gitlab/config
/gitlab.yml
1
2
3
4
5
6
7
8
9

production: &base
gitlab:
host: git.example.com
port: 80
https: false
...
email_from: gitlab@example.com
...
support_email: support@example.com

Note
If you specified a database name other than
gitlabhq_production when creating the PostgreSQL
database in the previous section, edit the
config/database.yml file to match with your database name.

4. Save and exit the file.


5. Make sure GitLab can write to the log/ and tmp/
directories:
1
2

sudo chown -R git {log,tmp}


sudo chmod -R u+rwX {log,tmp,tmp/pids,tmp/sockets,public/uploads}

6. Create directory for satellites:


1
2

sudo -u git -H mkdir /home/git/gitlab-satellites


sudo chmod u+rwx,g+rx,o-rwx /home/git/gitlab-satellites

7. Create the Unicorn, Rack attack, and PostgreSQL


configuration files:
1
2
3

sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb


sudo -u git -H cp config/initializers/rack_attack.rb.example confi
sudo -u git cp config/database.yml.postgresql config/database.yml

8. Make sure that config/database.yml is readable to git


only:
1

sudo -u git -H chmod o-rwx config/database.yml

9. Install the gems:


1
2

sudo gem install bundler


sudo -u git -H bundle install --deployment --without development t

10. Install GitLab shell, which is an SSH access and


repository management software for GitLab:
1

sudo -u git -H bundle exec rake gitlab:shell:install[v1.9.4] REDIS_

11. Open the GitLab shell configuration file:


1

sudo nano /home/git/gitlab-shell/config.yml

12. Check if the value of

gitlab_url

matches with the URL

of your server.
File excerpt: /home/git/gitlabshell/config.yml
1
2
3
4
5
6
7
8
9
10
11
12
13

3 de 6

user: git
gitlab_url: http://git.example.com/
http_settings:
self_signed_cert: false
repos_path: "/home/git/repositories/"
auth_file: "/home/git/.ssh/authorized_keys"
redis:
bin: "/usr/bin/redis-cli"
host: localhost
port: 6379
namespace: resque:gitlab
log_level: INFO
audit_usernames: false

13-05-2016 15:24

Install GitLab on Ubuntu 14.04 (Trusty Tahr)

https://www.linode.com/docs/applications/deve...

When you are satisfied with the configuration, save and


exit the file.
13. Initialize database and activate advanced features:
1

sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production

The command will display the following message


1
2
3

This will create the necessary database tables and seed the databas
You will lose any previous data stored in the database.
Do you want to continue (yes/no)?

Type yes and press Enter to continue.


14. Install the init script and make GitLab start on boot:
1
2

sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab


sudo update-rc.d gitlab defaults 21

15. Set up logrotate:


1

sudo cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab

16. Check application status:


1

sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=productio

Sample output
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

System information
System:
Ubuntu 14.04
Current User:
git
Using RVM:
no
Ruby Version:
2.1.2p95
Gem Version:
2.2.2
Bundler Version:1.6.3
Rake Version:
10.3.1
Sidekiq Version:2.17.0
GitLab information
Version:
6.9.2
Revision:
e46b644
Directory:
/home/git/gitlab
DB Adapter:
postgresql
URL:
http://git.example.com
HTTP Clone URL:
http://git.example.com/some-project.git
SSH Clone URL:
git@git.example.com:some-project.git
Using LDAP:
no
Using Omniauth: no
GitLab Shell
Version:
Repositories:
Hooks:
Git:

1.9.4
/home/git/repositories/
/home/git/gitlab-shell/hooks/
/usr/bin/git

17. Compile assets:


1

sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=product

18. Configure Git global settings for the git user:


1
2
3

sudo -u git -H git config --global user.name "GitLab"


sudo -u git -H git config --global user.email "gitlab@example.com"
sudo -u git -H git config --global core.autocrlf input

Note
Set the value for user.email according to what is set in
config/gitlab.yml

19. Start GitLab:


1

sudo service gitlab start

Set Up Nginx Virtual Host for


GitLab
Nginx is the only supported web server for GitLab. In this
section, you will create a new virtual host for GitLab and
activate the site.
1. Install Nginx if you havent installed it:
1

sudo apt-get install nginx

2. Copy the sample site config:


1

sudo cp lib/support/nginx/gitlab /etc/nginx/sites-available/gitlab

3. Open the config file:


1

sudo nano /etc/nginx/sites-available/gitlab

4. Modify the value for

server_name

to the fully-qualified

domain name of your server:


File excerpt: /etc/nginx/sites-available
/gitlab

4 de 6

13-05-2016 15:24

Install GitLab on Ubuntu 14.04 (Trusty Tahr)

https://www.linode.com/docs/applications/deve...

1
2
3
4

listen 80;
server_name git.example.com;
server_tokens off;
root /home/git/gitlab/public;

Save and exit the file.


5. Deactivate the default virtual host
1

sudo rm /etc/nginx/sites-enabled/default

6. Activate the site and restart Nginx to take effect


1
2

sudo ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enab


sudo service nginx restart

7. If Nginx failed to start with the following message


1

Restarting nginx: nginx: [emerg] could not build the server_names_h

Open /etc/nginx/nginx.conf and uncomment the following


line
1

server_names_hash_bucket_size 64;

Then restart Nginx.

Open GitLab on Your Browser


Double check the application status:
1
2

cd /home/git/gitlab
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production

If most of the items are green and some are purple (which is
okay since you dont have any git project yet), then you have
successfully installing GitLab. Below are the sample output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

Checking Environment ...


Git configured for git user? ... yes
Checking Environment ... Finished
Checking GitLab Shell ...
GitLab Shell version >= 1.9.4 ? ... OK (1.9.4)
Repo base directory exists? ... yes
Repo base directory is a symlink? ... no
Repo base owned by git:git? ... yes
Repo base access is drwxrws---? ... yes
Satellites access is drwxr-x---? ... yes
update hook up-to-date? ... yes
update hooks in repos are links: ... can't check, you have no proje
Running /home/git/gitlab-shell/bin/check
Check GitLab API access: OK
Check directories and files:
/home/git/repositories/: OK
/home/git/.ssh/authorized_keys: OK
Test redis-cli executable: redis-cli 2.8.4
Send ping to redis server: PONG
gitlab-shell self-check successful
Checking GitLab Shell ... Finished
Checking Sidekiq ...
Running? ... yes
Number of Sidekiq processes ... 1
Checking Sidekiq ... Finished
Checking LDAP ...
LDAP is disabled in config/gitlab.yml
Checking LDAP ... Finished
Checking GitLab ...
Database config exists? ... yes
Database is SQLite ... no
All migrations up? ... yes
Database contains orphaned UsersGroups? ... no
GitLab config exists? ... yes
GitLab config outdated? ... no
Log directory writable? ... yes
Tmp directory writable? ... yes
Init script exists? ... yes
Init script up-to-date? ... yes
projects have namespace: ... can't check, you have no projects
Projects have satellites? ... can't check, you have no projects
Redis version >= 2.0.0? ... yes
Your git bin path is "/usr/bin/git"
Git version >= 1.7.10 ? ... yes (1.9.1)
Checking GitLab ... Finished

Now you can open http://git.example.com on your browser.


GitLab will show you the login page.

5 de 6

13-05-2016 15:24

Install GitLab on Ubuntu 14.04 (Trusty Tahr)

https://www.linode.com/docs/applications/deve...

You can login using root as the username and 5iveL!fe for
the password.

Securing GitLab
Now that you have GitLab running on your server, you might
want to add SSL support to secure your GitLab site. Refer to
the SSL Certificates with Nginx (/docs/security/ssl/sslcertificates-with-nginx) guide to protect your site with SSL.

More Informaon
You may wish to consult the following resources for additional
information on this topic. While these are provided in the hope
that they will be useful, please note that we cannot vouch for
the accuracy or timeliness of externally hosted materials.
GitLab Community Edition (https://www.gitlab.com
/gitlab-ce/)
GitLab Documentation (https://www.gitlab.com
/documentation/)
GitLab Requirements (https://gitlab.com/gitlab-org/gitlabce/blob/master/doc/install/requirements.md)
GitLab Manual Installation (https://gitlab.com/gitlaborg/gitlab-ce/blob/master/doc/install/installation.md)
This guide is published under a CC BY-ND 3.0 (http://creativecommons.org/licenses
/by-nd/3.0/us/) license.

Get paid to write for Linode.


We're always expanding our docs. If you like to help people, can write, and want
to earn some cash, learn how you can earn $250 for every guide you write (/docs
/contribute) and we publish.

Get started in the Linode Cloud today.


Create an Account (hps://manager.linode.com/session/signup)

Overview
Resources
Company
Contact Us
(hps://www.linode.com
(hps://www.linode.com
(hps://www.linode.com
(hps://www.linode.com
/linodes)
/docs)
/about)
/contact)
Plans & Pricing (https://www.linode.com/pricing)
Guides & Tutorials (https://www.linode.com/docs)
About Us (https://www.linode.com/about)
855-4-LINODE (tel:+18554546633)
Features (https://www.linode.com/linodes)
Speed Test (https://www.linode.com/speedtest)
Blog (https://blog.linode.com)
(855-454-6633) (tel:+18554546633)
Add-Ons (https://www.linode.com/addons)
Forum (https://forum.linode.com/)
Press (https://www.linode.com/press)
Intl.: +1 609-380-7100 (tel:+16093807100)
Managed (https://www.linode.com/managed)
Chat (https://www.linode.com/chat)
Referral System (https://www.linode.com/referrals)
Email us (mailto:support@linode.com)
Professional Services System
(https://www.linode.com/professional-services)
Status (http://status.linode.com/)
Careers (https://www.linode.com/careers)
(https://facebook.com/linode) (https://twitter.com/linode) (https://plus.google.com/+linode/

2016 Linode, LLC


Terms of Service (https://www.linode.com/tos)
Privacy Policy (https://www.linode.com/privacy)
Security (https://www.linode.com/security)
Standards & Compliance (https://www.linode.com/compliance)

6 de 6

13-05-2016 15:24

Você também pode gostar