Sunday, April 19, 2009

How To: Create your own local SVN repository in GNU/Linux

This article tell you about creating your own local SVN repository in your GNU/Linux box.

Even though I personally like git, I like the SVN's idea of having all your code safe somewhere in a remote server!

I personally do a lot of coding, and several times I have lost my precious programs/codes due to some stupid mistakes I did or because I don't backup my code very often. Keeping a plain backup your code is a pain, having you to maintain several copies of them, based on their version.

Hence, several times I felt that, oh God, if at all I had my own SVN server somewhere?

So, today finally tried to create my own SVN server, and voila, in less than 5 minutes, my own SVN server was up and running! I never had thought that creating your own SVN server was a such easy task.

If you people are looking for the same, this article is for you!

Here is a step by step procedure to create your own SVN server.
  1. Install SVN package.

    You need to have subversion package installed.

    If you don't have it, install it using command

    sudo apt-get install subversion
  2. Create a SVN repository.

    Next step is to create a SVN repository. First decide where you want to store your repository data? I kept my SVN repository in my home directory, so that it also gets backed up with my home directory backup. So, You can also do the same or store your SVN repository in any other place of your choice.

    Use following command to create your own SVN repository in your home directory.

    svnadmin create ~/my_svn_repo
    This command will create a directory named 'my_svn_repo in' your home directory, with SVN's repository data inside it.

    If you want to store your SVN repository somewhere else, replace

    with your selected directory path.

  3. Change the SVN configuration for repository access.

    You need to configure the SVN to tell it about the read and write access to your repository.

    For this goto 'conf' directory present inside your SVN repository directory.

    cd ~/my_svn_repo/conf
    now open the file named svnserve.conf

    vi svnserve.conf

    gedit svnserve.conf
    and edit the file.

    un-comment following lines (remove # from the beginning of the line.)

    anon-access = read
    auth-access = write

    These lines tell about the read and write access to your SVN repository. 'anon-access = read' means anonymous users can read your SVN data.

    The possible values are 'read', 'write' and 'none'. The default value 'read' should be OK, as its a local repository. However, if your machine is in a network, you may want to change it to 'none' . ie;

    anon-access = none
    The second line 'auth-access = write' tells about the access rights of the authorized users. The default value of 'write' should be OK and it means authorized users can read/write back the data to the SVN repository.

    Below are some possible configurations;

    • The default configuration

      # anonymous users can only read the repository
      anon-access = read

      # authenticated users can both read and write
      auth-access = write

    • Restricted configuration

      # anonymous users aren't allowed
      anon-access = none

      # authenticated users can both read and write
      auth-access = write

  4. Configure the Authorization.

    un-comment following lines from the 'svnserve.conf' file opened in previous step.

    password-db = passwd
    This tells the SVN to read the user name and password from the file named 'passwd'.

  5. Setup the username and password.

    Open the file name 'passwd' present inside 'conf' directory of your SVN repository directory.

    Now un-comment the following lines.

    harry = harryssecret
    sally = sallyssecret

    This line tells the authorized user's name ans password. You can also add your username and password to this list. like

    raghu = mypassword
    or use existing username and password such as 'sally' and 'billy', oops.. 'harry'.

  6. Start the daemon process.

    Now enter following command to start the SVN daemon process.

    svnserve -d --root ~/my_svn_repo/
that's it. you can now checkout your own local SVN repository like any other SVN repository. Just use following URL to access your local SVN repository.


svn co svn://localhost my_svn_works
Creating SVN directory structure:(optional)

Like the SVN's general convention, I recommend you to create 3 different directories. They are trunk, tags and branches.

use following command to create them

svn mkdir branches tags trunk
now commit them to SVN.

svn commit
Making your SVN daemon process to start automatically with system.

The steps given above will start the daemon process, however if you restart your system, again you need to manually start the daemon process. Otherwise you can add a script to start the daemon process automatically with your system.

For this, You need to add a script to your /etc/init.d/

use following command to do it

echo "svnserve -d --root /home/raghunayak/my_svn_repo/" >> run_svnd && chmod +x run_svnd && sudo mv run_svnd /etc/init.d && sudo update-rc.d run_svnd defaults
In this command replace '/home/raghunayak/my_svn_repo' with with your SVN repository path.

To remove this startup script enter following command.

sudo update-rc.d -f run_svnd remove && sudo rm /etc/init.d/run_svnd
If you like this article, please leave a comment.. :)


Akash Agarwal said...

the commit option needs a -m "Commenrs things"

Kousik Maiti said...

I have one problem in running svn
This is my svnserve.conf file.
anon-access = read
auth-access = write
### The password-db option controls the location of the password
### database file. Unless you specify a path starting with a /,
### the file's location is relative to the directory containing
### this configuration file.
### If SASL is enabled (see below), this file will NOT be used.
### Uncomment the line below to use the default password file.
password-db = passwd

After changing everything mentioned by you when I run $svn co svn://localhost my_svn_repo
It gives the error
"svn: /home/kousik/my_svn_repo/conf/svnserve.conf:12: Option expected"
Can you please have a look?

Anas El Abboud said...

am really glad to read this article , it is useful and simple and led me step by step to get there .. thanks!

Hittesh said...


make sure there are no white spaces on the line anon-access = read and auth-access = write and password-db

Johnney Darkness said...

Note: after you

svn co svn://my_server my_repository

you missed an step. One must

cd my_repository

Otherwise you get:

svn: '.' is not a working copy

also I had to

export SVN_EDITOR=vim