Create a SVN repository with Ubuntu and SubVersion

Posted on Saturday August 06, 2011 / by Eric Potvin

Have you ever forgot to take a backup of your files? or even modify them and wanted to rollback to the previous version but, unfortunately, you don't have the previous version?

Whether it is a WebSite, personal documents, or any other project you working on, there is a simple solution to fix this issue; it's called SubVersion.

Some websites offers you to host your project for you, such as:

But if you want more control on your repository and you don't want to pay monthly cost, you should install SubVersion on your Ubuntu.

The process for installing subversion on Ubuntu and repository is simple. All the tools you will need to use SubVersion are included in the subversion package.

Get SubVersion

sudo aptitude install subversion

Setup a group

First, create a group named svn and then add your account to that group.

sudo addgroup svn
sudo gpasswd -a "$USER" svn

Setup the Repository home folder

In order to be able to use, create a repository home folder:

sudo mkdir -p /svn/repository

Give access to the svn group.

sudo chgrp -R svn /svn/repository
sudo chmod -R 770 /svn/repository

To make sure the changes you made takes effect relating the security svn group, A logout of the GUI/shell and re-login is sufficient to re-read the permissions.

Don't forget to bookmark this page first **

Create a new repository project

To create your project repository, use the svnadmin command:

svnadmin create /svn/repository/my_project

Create a SVN user

You will also need user who will need access to the repository. To create a user, use the following command:

vi /svn/repository/my_project/conf/svnserve.conf

and add to that file these three lines:

anon-access = none
auth-access = read
password-db = passwd

After, create a password file or edit the current one:

vi /svn/repository/my_project/conf/passwd

In that file add a line for your user:

myuser = mypassword

Setup the SVN server Daemon

You can run manually the daemon on the host computer using the svnserve command:

svnserve -d -r /svn/repository

Or, you can setup to run automatically:

Simply create a new file (I called mine svnserve) and type the command you’d like to run

cd /etc/init.d/
sudo echo "svnserve -d -r /svn/repository/my_project" > svnserve

Make the script executable

sudo chmod +x svnserve

Add the script to the boot sequence

sudo update-rc.d svnserve defaults

Import Your Project

Now that you have your project repository up and running, you will be able to add files and folders in it.

svn import /svn/repository/my_project file:///repository/my_project

Checkout Your Project

Now your project is stored in your repository. You will need to check it out to work on it and make changes.

cd /my/www/path/
svn co file:///repository/my_project my_project

Create a trunk and branches folders

If you are the only user working on your project, you can create the trunk folder:

cd /my/www/path/
mkdir trunk
svn add trunk
svn commit -m "Added trunk folder"

If you have more than one developers working on your project, you can create the branches folders.

cd /my/www/path/
mkdir branch
svn add branch
svn commit -m "Added branch folder"

Done! Enjoy your repository and feel free to update your code without thinking of taking backups every time the code has change.