Note: I have created a script to automate this process. The post regarding the script can be found here.
This guide is for setting up a Subversion (SVN) repository in Ubuntu. Subversion is a version control system which enables multiple users to modify the same document. Therefore, a tool such as Subversion comes in really handy when developing software on a team. Also, Subversion can be a life saver when you need to revert back to older versions of a document (e.g. you made some changes to your code and now everything is broken).
This guide is for creating a repository that requires authentication for all access. This is unlike open source SVN repositories which allow anonymous read access. If you desire, access permissions can be changed at the end of step 3.
Also, this guide does not use SSL and therefore is only recommended for secure local networks (e.g. behind a router at your house or corporate network) if you are working on something important. Maybe I will add SSL to this tutorial in the future.
When creating this guide I used Ubuntu 6.06, Apache2 2.0.55, and Subversion 1.3.1. Ok, on with the walkthrough.
1) Install Apache2, Subversion, and the Apache modules for Subversion. You can install these packages via the Synaptic Package Manager or you can execute the following commands in the terminal.
sudo apt-get install apache2
sudo apt-get install subversion
sudo apt-get install libapache2-svn
2) Now we need to edit the libapache2-svn configuration file. To open the file, execute the following command.
sudo gedit /etc/apache2/mods-available/dav_svn.conf
3) Edit the file in the following locations:
To enable the repository:
# DAV svn
To set the path of the repository:
Note: This guide uses /svn for the Subversion repository. You can create the repository in any directory you wish, just make sure to change the path throughout the rest of the guide to represent your chosen directory.
Uncomment & Change…
# SVNPath /var/lib/svn
To enable user authentication:
# AuthType Basic
# AuthName "Subversion Repository"
# AuthUserFile /etc/apache2/dav_svn.passwd
AuthName "Subversion Repository"
To make readers & committers authenticate themselves:
<LimitExcept GET PROPFIND OPTIONS REPORT>
4) Now we need to restart Apache.
sudo /etc/init.d/apache2 restart
5) Next we need to create the Subversion repository. As said before, in this guide we are going to create the repository in the directory /svn of the root directory. This command will create several SVN files and directories in /svn.
sudo mkdir /svn
sudo svnadmin create /svn
6) Then we have to change the ownership of the directory so that Apache can write to it.
sudo chown -R www-data:www-data /svn
7) Ok, let’s create an authenticated user that will have access to the repository. The following command will create a user named “bigbamboo”.
Note: You will be prompted for a password.
sudo htpasswd2 -c /etc/apache2/dav_svn.passwd bigbamboo
8) Now let’s create a project. Probably the easiest way to create a project is to import files that you would like to add to SVN. If you would like to learn more about the SVN import command please visit here.
- “/home/bigbamboo/myproject” is the location of the files we want to add to the repository.
- “projectname” is the name of the project we are adding to Subversion.
- “-m” is used for adding a message to the commit.
- “bigbamboo” is the username and “mypassword” is the password of the authenticated user.
Note: The following command is one line.
svn import /home/bigbamboo/myproject http://localhost/svn/projectname -m "creating repository" --username bigbamboo --password mypassword
9) You have now created a SVN repository containing a project. To view the files in your Subversion repository you can go to http://localhost/svn/projectname.
From here you are on your own with adding, committing, updating, and reverting your documents. All of those commands can be done via the command line but there are several GUI applications that really help out. I highly recommend RapidSVN for Mac/Linux, and TortoiseSVN for Windows.
If you notice any errors in the guide please let me know. Also, I am always open to any suggestions as I am still learning too.