How to install gitweb in Ubuntu
Recommended Ubuntu book
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.
December 23rd, 2011 20:40
Hey,
Thanks for this, but when I try to restart apache after editing conf.d/gitweb, I get the following error –
RewriteRule: cannot compile regular expression ‘^/gitweb/([a-zA-Z0-9_-]+.git)/?(?.*)?$’ [fail]
How can I fix this?
Thanks.
Abhi
January 2nd, 2012 05:52
I’m getting;
/etc/init.d/apache2 restart
Syntax error on line 2 of /etc/apache2/conf.d/gitweb:
RewriteRule: cannot compile regular expression ‘^/gitweb/([a-zA-Z0-9_-]+.git)/?(?.*)?$’
Action ‘configtest’ failed.
The Apache error log may have more information.
…fail!
Do you know what is wrong?
January 2nd, 2012 06:00
I used the following line instead and all is well;
RewriteRule ^[a-zA-Z0-9_\-]+\.git/?(\?.*)?$ /gitweb.cgi%{REQUEST_URI} [L,PT]
February 18th, 2012 02:09
Nice, thanks for the update. I appreciate the input.
February 18th, 2012 02:12
@Adhi, check out Michael’s solution and give it a try. Let us know if it worked.
February 20th, 2012 19:00
Having problems getting Apache restarted.
—
sudo /etc/init.d/apache2 restart
* Restarting web server apache2 Syntax error on line 8 of /etc/apache2/conf.d/gitweb:
AllowOverride not allowed here
—
This is what my /etc/apache2/conf.d/gitweb looks like:
——
RewriteEngine on
RewriteRule ^[a-zA-Z0-9_\-]+\.git/?(\?.*)?$ /gitweb.cgi%{REQUEST_URI} [L,PT]
Alias /gitweb /usr/share/gitweb
Options Indexes FollowSymlinks ExecCGI
DirectoryIndex /cgi-bin/gitweb.cgi
AllowOverride None
June 12th, 2012 20:57
I think your blog engine filtered out the lines that had gt and lt.
In this comment, replace [ with greater than and ] with lesser than:
[Directory /homeofyourgitrepos]
Options Indexes FollowSymlinks ExecCGI
DirectoryIndex /cgi-bin/gitweb.cgi
AllowOverride None
[/Directory]
September 26th, 2012 01:37
If you used the same directory structure, perhaps
Alias /gitweb /home/git/repositories should be used instead of Alias /gitweb /usr/share/gitweb
February 19th, 2013 19:50
Hey, just confirming that Michael’s solution worked for me. Thanks!
August 28th, 2013 12:40
Follow the solution of the john with an amendment in
Options Indexes FollowSymLinks ExecCGI
DirectoryIndex / cgi-bin/gitweb.cgi
AllowOverride None