How to install gitweb in Ubuntu
After being told that I live in the stone age for using svn, I decided to try out git. Finally I got some time to continue learning git and setting the new environment. As a step one, we learned how to install git on Ubuntu. Then, I decided that I wanted to host my own repositories and we learned how to set up gitosis on Ubuntu. Now, after updating to Ubuntu 11.10 – Oneiric Ocelot, I am ready to continue setting up everything I need to start conveniently using git. So, in this post, I will be setting up the gitweb and documenting the process.
Gitweb is a convenient GUI that allows us to quickly see the project and diffs right in the browser. Before we move on to installing git web, make sure you have installed apache. Now, lets move on to installing gitweb:
sudo apt-get install gitweb
Now lets look in our /var/www folder:
cd /var/www ls
I didn’t have gitweb folder here, so I created it:
sudo mkdir /var/www/gitweb
gitweb files should be in /usr/share/gitweb and we need them in our /var/www/gitweb, so lets create a symbolic link that will point to the files:
cd /var/www/gitweb sudo ln -s /usr/share/gitweb/* .
To check if these are symbolic links, you can type:
ls -l
it should show what these files are linked to.
Next, locate the path to your git repositories. As per our install, we have it in /home/git/repositories. So, lets edit gitweb config to point to the right directory:
sudo gedit /etc/gitweb.conf
and replace:
$projectroot = "/var/cache/git";
to our path to git repositories, /home/git/repositories in my case to:
$projectroot = "/home/git/repositories";
Save the file and lets move on to next step – editing apache configuration. Open apache config for gitweb:
sudo gedit /etc/apache2/conf.d/gitweb
And edit it as follows (replace the paths if yours are different):
RewriteEngine on RewriteRule ^/gitweb/([a-zA-Z0-9_\-]+\.git)/?(\?.*)?$ /cgi-bin/gitweb.cgi/$1 [L,PT] Alias /gitweb /home/git/repositories Options Indexes FollowSymlinks ExecCGI DirectoryIndex /cgi-bin/gitweb.cgi AllowOverride None
and save. Now its time to restart apache to apply the changes:
sudo /etc/init.d/apache2 restart
I got an error at first saying:
Syntax error on line 1 of /etc/apache2/conf.d/gitweb:
Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
Action 'configtest' failed.
The Apache error log may have more information.
...fail!
Which was because I needed to add rewrite package to apache:
sudo a2enmod rewrite
This time apache started with no errors.
Now you should be able to go to http://localhost/gitweb and see the gitweb page. If you have no public repositories yet, you may see “404 – No projects found” notice. To test it out, I went to my repo folder:
cd /home/git/repositories/
and changed the permissions on my gitosis-admin.git:
sudo chmod -R 755 gitosis-admin.git
Refresh the localhost/gitweb and ta-da! It shows a repository where I could click around and check things out. Since I didn’t want this repo to show publicly, I had to change the permissions back to:
sudo chmod -R 750 gitosis-admin.git
This is it for now. In the next git series posts I will try to go over creating new repositories, adding users, general git usage, installing redmine for project management and anything else I may find useful.