Setting up an Apache Subversion (SVN) server for access using svn:// with client applications like TortoiseSVN is actually pretty simple. The official Ubuntu Documentation covers a lot more than this simple setup but this is enough to get something up and running quickly without worrying about WebDAV or HTML access. The odyniec.net tutorial is also really useful and provides the init.d startup script I used to make the SVN server run at boot.
The steps are; install subversion, create the repository directories, set access control, set subversion to run at boot.
To install subversion in ubuntu just run:
sudo apt-get install subversion
Now create a directory to hold your subversion repositories, in my case I used “/home/svn”:
sudo mkdir /home/svn
Create a repository folder, for example “svnrepo1″, within this directory:
sudo mkdir /home/svn/svnrepo1
Now you can use the “svnadmin” program that comes as part of the subversion package to create a SVN repository within this folder:
sudo svnadmin create /home/svn/svnrepo1
The configuration file for the repository is created as ”/home/svn/svnrepo1/conf/svnserve.conf” and contains the option to enable password protection as well as a lot of other useful settings. The important lines to uncomment to force password access are:
anon-access = none
auth-access = write
By setting “anon-access” to “none” you force people to enter passwords on connecting to the SVN. Now set up password protected access by uncommenting the following:
password-db = passwd
Settings “password-db” to “passwd” means the list of users and passwords in the “/home/svn/svnrepo1/conf/passwd” file will be used to check if someone has access. In a lot of cases it makes sense to keep this “passwd” file somewhere else so it can be used for all your repositories. In my case I set it to:
password-db = /home/svn/passwd
Just make sure to set the passwd file to be only readable by root:
sudo chmod 600 /home/svn/passwd
The “passwd” file is actually a very simple text file and looks something like:
[users]
harry = harrypassword
sally = sallypassword
Once the SVN server is configured and a repository set up as above you can run the SVN server using:
svnserve -d –foreground -r /home/svn
To make sure the SVN server starts at boot you need to set up init.d. Do this by creating and editing a file “/etc/init.d/svnserve” (I use “nano” to do my text editing on the command line):
sudo nano /etc/init.d/svnserve
Now paste in the contents of the odyniec.net init.d script. This script covers everything you need to start, stop and restart the “svnserve” program at boot so your SVN server can listen to all svn:// connections. There are alternatives to using this script, but this works and is simple to set up. Make sure you change the line with “DAEMON_ARGS” to point to the right place of “/home/svn”:
DAEMON_ARGS=”-d -r /home/svn”
Now tell Ubuntu to update its startup routine to include this new script:
sudo update-rc.d svnserve defaults
Reboot the server to make sure everything is working as expected.
You can now start, stop or restart the automatically booted SVN server using the following commands:
sudo /etc/init.d/svnserve start
sudo /etc/init.d/svnserve stop
sudo /etc/init.d/svnserve restart
Connecting to your SVN server can be done using something like TortoiseSVN and the URL you use to connect to the “svnrepo1″ repository you just set up is:
svn://your.serv.er.ip/svnrepo1
There is a lot more you can do with the SVN configuration, such as adding group support etc, but this is the quickest way to set up a standard SVN server on Ubuntu to accept svn:// connections using “svnserve”.