How To Create An Ubuntu Subversion Server
By Daniele Salatti
Article Date: 2009-03-18
Subversion (SVN ) is a version control system initiated in 2000 by CollabNet Inc . It is used to maintain current and historical versions of files such as source code, web pages, and documentation. Its goal is to be a mostly-compatible successor to the widely used Concurrent Versions System (CVS).
Subversion is well-known in the open source community and is used on many open source projects, including Apache Software Foundation , KDE , GNOME , FreeBSD , GCC , Ruby , and Tigris.org . Google Code also provides Subversion hosting for open source projects.
Subversion is released under the Apache License , making it free software .
Main features
Let's begin
Installation is straightforward. All the packages you need are available in the official Ubuntu repositories.
The first step is to install subversion itself:
view sourceprint
1.sudo apt-get update
2.
3.sudo apt-get install subversion
Next step is to create a repository. We will use this repository (named "repo") for testing purposes. Usually I put my repositories in /var/svn when I set up a Subversion server, but you may change it at your convenience.
view sourceprint
1.cd /var
2.
3.sudo mkdir svn
4.
5.sudo svnadmin create /var/svn/repo
To control who has access to the repository, we will add a user who will own all the repository files. This will also add a group with the same name as the user.
view sourceprint
1.sudo adduser --system --no-create-home --group svn
This will create a user with no password (you will not be able to perform a log-in with the user "svn"), uses the right UIDs for system accounts, and skips creating the home directory (we don't need it).
(set password is you want # sudo passwd svn)
Now change the ownership of the repository files with the following command:
view sourceprint
1.sudo chown -R svn.svn /var/svn
In order for your users to be able to access the repository you need to add them to the svn group. If you skip this step your users wont be able to write in the repository. When you are done you need to install an ssh server, because clients will connect using ssh .
(# usermod -a -G svn
useradd -G {group-name } new username
)
view sourceprint
1.sudo apt-get install openssh-server
Now you should be able to connect to the repository using ssh:
view sourceprint
1.svn co svn+ssh://username@
To install subversion, open a terminal and run the following command:
sudo apt-get install subversion libapache2-svn
We’re going to create the subversion repository in /svn, although you should choose a location that has a good amount of space.
sudo svnadmin create /svn
Next we’ll need to edit the configuration file for the subversion webdav module. You can use a different editor if you’d like.
sudo gedit /etc/apache2/mods-enabled/dav_svn.conf
The Location element in the configuration file dictates the root directory where subversion will be acessible from, for instance: http://www.server.com/svn
The DAV line needs to be uncommented to enable the dav module
# Uncomment this to enable the repository,
DAV svn
The SVNPath line should be set to the same place your created the repository with the svnadmin command.
# Set this to the path to your repository
SVNPath /svn
The next section will let you turn on authentication. This is just basic authentication, so don’t consider it extremely secure. The password file will be located where the AuthUserFile setting sets it to… probably best to leave it at the default.
# Uncomment the following 3 lines to enable Basic Authentication
AuthType Basic
AuthName “Subversion Repository”
AuthUserFile /etc/apache2/dav_svn.passwd
To create a user on the repository use, the following command:
sudo htpasswd2 -cm /etc/apache2/dav_svn.passwd
Note that you should only use the -c option the FIRST time that you create a user. After that you will only want to use the -m option, which specifies MD5 encryption of the password, but doesn’t recreate the file.
(use "htpasswd" is "htpasswd2 command not found")
Example:
sudo htpasswd2 -cm /etc/apache2/dav_svn.passwd geek
New password:
Re-type new password:
Adding password for user geek
Restart apache by running the following command:
sudo /etc/init.d/apache2 restart
Now if you go in your browser to http://www.server.com/svn , you should see that the repository is enabled for anonymous read access, but commit access will require a username.
If you want to force all users to authenticate even for read access, add the following line right below the AuthUserFile line from above. Restart apache after changing this line.
Require valid-user
Now if you refresh your browser, you’ll be prompted for your credentials:
You now have a working subversion server!
Before you start using Subversion, make sure you make the repositories owned by Apache. Apache is the one who wil access the repositories physically. This is really easy:
$ sudo chown -R www-data.www-data /var/lib/svn