Tags:

Create a SVN repository with Ubuntu and SubVersion

Sunday, August 7, 2011 EDT (Updated on: Tuesday, January 24, 2012 EST)

by: Eric Potvin

Tags: ubuntu linux svn

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:
  • Google Code
  • SourceForge

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

Last comment by: Eric

comments (2) Comments Feeds
Share this article:
Thanks to Philipp Hagemeister for updating this article.
Comment by Eric Sunday, September 18, 2011 EDT
0
Thanks for the good tutorial. One remark, though. In line "sudo svnadmin create /svn/repository/my_project" there should not be sudo. The user is now in the right group and should be able to create repos. Otherwise there would be a clash with the command in the next line, where you want to create a conf file - permissions will not allow that if a my_project repo was created by root. Right?
Comment by AdrianB Tuesday, January 10, 2012 EST
0

Add a comment

* If your comment require a response from us, please make sure you leave your email

Captcha

* is required
The posting of advertisements, profanity, or personal attacks is prohibited.
Please review our terms of use

Latest Articles

Top Articles

Category List

Top of the page
Loading, please wait ...