Installing and Configuring Subversion on Ubuntu

Written on the 12th July, 2008 by Ben McRedmond.
Categories: General. Tags: , , , , , ,
You can leave a comment.

For a long time I’ve hosted my sites on a MediaTemple VPS or Virtual Private Server. For a pricey $50 a month you get a pretty nice package and 24/7 support but recently I was turned onto Slicehost. They offer great plans for very reasonable prices and great support too (always important).

They also offer a choice of operating systems, not forcing me to use my now least favourite operating system: centOS. I chose ubuntu and following on from last weeks post about project management, I will talk about how to install and configure a subversion server running on Ubuntu 8.0.4.

I’m assuming you have basic developer tools installed and have a good enough concept of the command line + *nix. Start by installing subversion.

# apt-get install subversion

This gives us all the subversion admin and client tools. We’ll start by creating a central location for our repositories under /home/svn.

# mkdir /home/svn
# cd /home/svn

Now lets create a repository, replace myrepo with the name of your repository.

# svnadmin create myrepo

If you do an ls in this directory you’ll see subversion created a new directory called “myrepo”. We’re going to setup http access to our repository, so we need to ensure apache can read and write the files.

# cd /home
# chown -R www-data:www-data svn
# chmod -R 770 svn

We need to create some users to login to our subversion server, after running each htpasswd command it will prompt for a password which will be the login password for the user.

# cd /home/svn
# htpasswd -c .htpasswd firstuser
# htpasswd .htpasswd seconduser
# htpasswd .htpasswd thirduser

Now we have our repository setup we need to connect apache to it. I’m assuming you have apache setup and installed. Next we need to install apache subversion bindings and enable webdav.

# apt-get install libapache2-svn
# cd /etc/apache2
# a2enmod dav

Finally we need to configure apache.

# cd /etc/apache2/sites-available
# nano svn.mydomain.com

This will create a new file called svn.mydomain.com and open a blank file in a text editor. Copy the below into it and replace yourdomain with the correct value wherever mentioned.

<VirtualHost *:80>
 
  	# Admin email, Server Name (domain name) and any aliases
  	ServerAdmin admin@yourdomain.com
  	ServerName  svn.yourdomain.com
 
	<Location />
		AuthType Basic
		AuthUserFile /home/svn/.htpasswd
		AuthName "Dev Team Only"
		require valid-user
		DAV svn
		SVNPath /home/svn/hippstr/
	</Location>
 
</VirtualHost>

Now we need to enable and restart apache.

# cd /home/apache2
# a2ensite svn.yourdomain.com
# apache2ctl graceful

If everything went well we should now be able to access are subversion server at svn.yourdomain.com. But we need a subversion client on our desktop machine to access the repository.

Subversion clients

My favourite gui subversion client is currently an os x app called Versions. Which I’ll talk a little about below but if you’re not on os x I would recommend either Tortoise SVN on windows or the standard subversion command line client on any os. Available here.

You also need to learn how to use subversion by reading the free subversion book, there’s a small learning curve to understanding subversion and integrating it into your workflow but you’ll get used to it eventually!

To setup subversion in versions click “add new repository bookmark” and enter the following information. The user and password are what you set above when running the htpasswd commands.

There’s a small learning curve now to understanding subversion, as mentioned above and it’s all explained better than I could ever explain it in the subversion book mentioned above. Good luck! Ask any questions you still have in the comments.


One Comment

  • 1.

    […] workflow but once you get it, it’s a lifesaver. If you don’t know about subversion see my previous article on getting started. I haven’t gone into detail on how to do things because this article is […]

    Posted on October 18th, 2008
    By Ben McRedmond.com

Leave a Reply