Jun 25
How To: Host a Subversion Repository in Ubuntu Hardy
Have you ever wanted to set up a subversion repository on your home computer? Whether it be for a new software project, versioning your personal documents, or any other reason, there are many benefits to using version control. Some free websites that will host your project for you, such as SourceForge or Google Code, but it’s often necessary to have a little bit more control.
I set up a subversion repository for a new project the other day, and the process was relatively painless. I’m using a standard Ubuntu Hardy Heron 8.04 desktop setup, with OpenDNS and DD-WRT for port-forwarding, and without an Apache web server. Keep reading to host your own subversion repository server.
The entire process for setting up a subversion server and repository is relatively simple on Linux, and should take you no more than one hour. I’ve broken this tutorial into a few different segments, so you can concentrate on only the parts you are interested in.
- Initial Setup
- Adding the First Repository
- Configuring Your Repository
- Access from the Host Computer
- Access from a LAN Computer
- Access from Outside the LAN
- Final Steps
Initial Setup
In Ubuntu Hardy, all the tools you will need for a basic subversion server are included in the subversion package. If you haven’t already you can install it with the following command:
sudo aptitude install subversion
The next steps is to create a new group that will be responsible for subversion tasks.
- From the Panel, navigate to System > Administration > Users and Groups
- If necessary, unlock the dialog, and then click “Manage Groups”
- Click “Add Group”. Create a group named “subversion”, and add yourself to it.
- Log out and back re-log in for the changes to take effect.
Now that the group is created, the next step is to create the directory structure where our repositories will live. You can create the folder wherever you’d like, but a good choice is /home/svn
- In a terminal, create your new folder, using the commands:
cd /homesudo mkdir svn
That’s it for the basic setup. Of course, the subversion server isn’t useful until we add a repository or two..
Adding the First Repository
In subversion, each project or directory structure is contained within its own repository. Each repository (or repo for short) maintains its own access control, versioning, and logs. Let’s create a new repository called “my-project”
First, we need to create the repository folder:
cd /home/svnsudo mkdir my-project
Finally, we use the “svnadmin” command to create some base files and configure the repository.
sudo svnadmin create /home/svn/my-project
Now, change the access permissions to give the subversion group the proper settings:
sudo chgrp -R subversion my-projectsudo chmod -R g+rws my-project
This is the minimum work required to initialize a repository. At this point, you could start accessing your repository from the host computer. But, you may also want to fine-tune your configuration below.
Configuring Your Repository
At this point, you should have a working repository. However, there are still a few options you might want to tweak. In particular, the access permissions. By default, a fresh repository will be readable by anyone and writable by authorized users. To change these settings, open /home/svn/my-project/conf/svnserve.conf in your favorite text editor– you can use the command:
gedit /home/svn/my-project/conf/svnserve.conf
The lines that control access restrictions look like:
# anon-access = read# auth-access = write
These two lines control anonymous access and authenticated access, respectively. To change from the default behavior for each value, remove the leading ‘#’ character, and set the right-side value to ‘read’, ‘write’, or ‘none’, for read-only, read-write, or no access, respectively. When you are finished, you can save the file and close it.
If you plan on using authenticated access to your repository, you will need to set up at least one username and password. To do so, open the /home/svn/my-project/conf/passwd file in a text editor:
gedit /home/svn/my-project/conf/passwd
To create a username, simply add a line to the bottom of the form:
username = password
There are a few examples already in the file, but commented out. You may add as many usernames as you need. When you are finished, save the file and close it. These are the basic configuration steps you’ll need, although more are discussed in the Final Steps.
Access From the Host Computer
At this point you are ready to test out your new repository. Any configured repositories should be accessible from the host computer as-is. You can test it out by checking-out your first working copy:
svn checkout file:///home/svn/my-project ~/my-project-wc
Perhaps you would like to add a “trunk” directory, where you will develop your project:
cd ~/my-project-wcmkdir trunksvn add trunksvn commit -m "Add a trunk directory for development."
Depending on your configuration above, you may be asked for a user name and password. You should use the values you entered in the passwd file.
Access from a LAN Computer
If you have another laptop or desktop in your home, then you may want to also access your repository from it. Fortunately, extending your subversion server within a LAN isn’t too much more complicated, using the svn:// protocol.
First, you will need to set up a daemon on the host computer to listen for connections, using the svnserve command:
svnserve -d -r /home/svn
This starts a process in the background that will silently wait for connections to the subversion server. To run in the foreground, simply use the –foreground parameter.
Then, you can connect to your repository from any computer within your LAN, using the syntax:
svn checkout svn://my-host/my-project ~/my-project-wc
where my-host is the name your host computer. Note that it is also possible to connect using a Windows or Mac machine, with the same syntax.
Access from Outside the LAN
If others outside your LAN will need to use the repository, or you often work away from home, then you’ll want to set up your subversion server for access anywhere. This will require tweaking some setting in your router. Particularly, you will need to forward TCP port 3690 to the machine hosting the subversion server. I used a DD-WRT based router, but most router interfaces are similar.
- Open the web-based router control panel, and enter the administrative username and password. Generally, the address is similar to http://192.168.1.1
- Locate the settings for “Port Forwarding”. If you are using DD-WRT, navigate to NAT / QoS > Port Fowarding
- Add a new entry to forward TCP port 3690 to the IP address of your subversion host computer, with destination port also 3690. This is the default port that subversion listens on. Then, save your settings and close.
You can test your forwarded port by trying to connect using your external IP address. There are many websites that will help you find your external IP, such as http://whatismyipaddress.com/ Note that it shouldn’t start with 192.168…
svn checkout svn://{external-ip}/my-project ~/my-project-wc
If you plan to work away from home frequently, you may want to set up dynamic DNS– this provides you with a personalized hostname, so you don’t need to remember a cryptic IP address. If you are using DD-WRT, you can follow the following steps:
- Go to DynDNS.com and sign up for an account. Create a “Dynamic DNS” (DDNS) hostname.
- Log in to your DD-WRT admin panel as before, and navigate to Setup > DDNS.
- Enter your DynDNS account details into the appropriate fields.
- Hit “Apply Settings”– the DDNS status should show that your IP has updated successfully.
Once you have your DDNS hostname set up, you can use it to access your subversion repository, using the command:
svn checkout svn://{ddns-hostname}/my-project ~/my-project-wc
This should be accessible both inside and outside your LAN.
Final Steps
At this point, you should have a subversion repository up and running. However, there are still a few features you may be interested in.
To access your repository using the svn:// syntax, you will need to have the svnserve daemon running. You can easily set the command to run when you log in with the following steps:
- From the desktop panel, open System > Preferences > Sessions.
- Click the “Add” button to add a new Startup program.
- In the “Name” field, enter “Subversion Server Daemon”
- For the command, enter: svnserve -d -r /home/svn
- And in the description, add a useful summary such as “Listen for connections to the subversion repository”.
Now, your subversion repository will be accessible as long as your username is logged in.
Once you being using multiple repositories, you may want to share the same username database for them. For this, you will need to configure repositories to use the same “passwd” file and belong to a common realm. For each of the repositories that will share a username database:
- Open a terminal in the root directory of the repository:
cd /home/svn/{repository-name}
- Open the svnserve.conf file located in the conf directory using a text editor:
gedit conf/svnserve.conf
- Find and uncomment the line that starts with “passwd-db”. Enter the location of the passwd file that will be shared between databases. You may enter an absolute path, or a path relative to the conf directory.
- Find and uncomment the line that starts with “realm”. Set the right side to a name that will be shared between each of the repositories accessing the common database. You may use a descriptive name such as “work-repository-realm”.
Finally, you may want to use subversion from the file browser. Although not strictly part of setting up a server, it is often useful to install the Nautilus subversion plugin. This will allow you to right click on a subversion working copy folder and perform common subversion tasks. To install, simply enter the command:
sudo aptitude install nautilus-script-collection-svn
Update: Actually, it’s a little bit tricky to get the Nautilus plugin working. If you’re having trouble, check out these instructions to enable SVN access in Nautilus.
And that’s it! Now, start using your repository and enjoy the benefits of version control. Are there any other tips that you would offer for setting up subversion? Let’s hear your experiences in the comments.
If you're new here, you can subscribe to automaticable's RSS feed by clicking here. Or, you can get post updates through your email. Thanks for visiting!

















July 18th, 2008 at 2:28 pm
This is a sublimely straightforward and simple how-to. Kudos to the author.
I’ve wanted to switch from an outdated version of Perforce to svn for a long time. I’ve bought two books and read lots of online documentation, and I’m no stranger to Linux, having used Ubuntu daily for over two years. But every other reference has been full of “you could do this, or you could do that, or this other thing’, and I quickly get lost in the details of BerkeleyDB vs. FSFS, or trying to figure out how to set up my first repository without jeopardizing my ability to set up other repositories on the same machine in the future.
This article explains exactly what I wanted to do. Using an existing Hardy installation, in about 20 minutes I was able to set everything up for the first repository, including three passworded user accounts, and do a checkout onto a Mac client. Now the project can move forward, and if I need to learn more, I can do it later.
Fantastic job!
August 28th, 2008 at 12:02 pm
Wonderful tutorial. Thanks a ton for making things easier for the “rest of us”
Cheers!
September 15th, 2008 at 4:47 pm
[...] your files versioned and backed up in a central repository is essential. I’ve written about how to set up your own subversion repository, but you can go a step further and install a graphical interface to use subversion right within [...]
November 24th, 2008 at 1:18 pm
Hi,
Thanks for the tutorial. It is a great one to set-up SVN instantly.
One quick question: How do I enable post-commit mail notifications?
Thanks,
November 25th, 2008 at 11:01 am
Hi Nithya, glad you found the tutorial helpful.
For mail notifications, there is already a hook “mailer.py” distributed with the subversion package, although there is also a more robust version called svnmailer. You can install it via the svnmailer package.
The setup requires a couple more configuration file edits. First of all, in svn repository configuration folder (/home/svn/my-project/conf), you need to create a new file “svnmailer.conf”. Here is the layout of my file:
[general]config_charset = iso-8859-1
smtp_host = smtp-host.my-isp.net
smtp_user = my-smtp-usename@my-isp.net
smtp_pass = my-smtp-password
[author table]scott = scott@scotts-isp.net
kyle = kyle@kyles-isp.net
[maps]from_addr = [author table]
[defaults]from_addr = svn-admin@my-isp.net
to_addr = scott@scotts-isp.net kyle@kyles-isp.net
generate_diffs = add modify copy
long_mail_action = 100000 showurls/truncate
This is for a very basic configuration. You should be able to guess at which fields need to be modified for your own configuration (setup your SMTP mailer info, setup the user accounts to mail for, etc.) For an advanced configuration, see the full svnmailer documentation.
The other file you’ll need to modify is /home/svn/my-project/hooks/post-commit. There is a “template” version available which you can use by copying it with the following command (inside the /home/svn/my-project/hooks directory):
cp post-commit.tmpl post-commitThen open it and scroll down to the very bottom. Edit it so that the only uncommented lines (ones that don’t start with ‘#’) look like:
REPOS="$1"REV="$2"
/usr/bin/svn-mailer --commit --config /home/svn/my-project/conf/svnmailer.conf \--repository "${REPOS}" --revision "${REV}" &
After that you should be ready to go! Try committing to your repository to make sure everything works out.