$ sudo apt-get install subversion
It requires to need a directory for your repositories, as well as other Subversion-related files. Recommended use
/usr/local/svn for this purpose, and you can choose either. I prefer
/home/svn, as I like to keep /home for home directories of real users of the system.
$ sudo mkdir /usr/local/svn
Inside this directory, create another one to hold your repositories:
$ sudo mkdir /usr/local/svn/repos
Now, you need to set some access permissions on those directories. You only want to allow certain users of your system (that is, yourself and the other developers) to access the repositories, so add a new group for those users. Name the group
$ sudo groupadd svn
Then, change the group ownership of
/usr/local/svn/repos to the new group using the
$ sudo chgrp svn /usr/local/svn/repos
The members of the
svn group also need write access to the
repos directory, so use
chmod to add the write permission for the group:
$ sudo chmod g+w /usr/local/svn/repos
Additionally, you need to make sure that all new files and directories created in the
repos directory (in other words, anything committed to the repositories) will also be owned by the group. To accomplish this, use
chmod again to set the set-group-ID bit on the directory, which causes any file created inside it to have the same group ownership as the directory itself. Effectively, everything in
repos will belong to the
$ sudo chmod g+s /usr/local/svn/repos
OK, so you now have the repositories directory with proper permissions, ready to be used by the
svn group. Go ahead and add yourself to the group:
$ sudo usermod -a -G svn michal
However, your new group membership will not be effective for the current session, so you need to log out and log back in. When you’re back, you can verify that your account is recognized as a member of the svn group:
michal adm dialout cdrom plugdev lpadmin admin sambashare svn
If the other developers have user accounts on your server, add them to the group too:
$ sudo usermod -a -G svn jimmy $ sudo usermod -a -G svn craig
If they don’t, they will still be able to access the repositories, but only using the basic svn protocol, not the secure svn+ssh method.
Creating a Test Repository
You can now create a repository. In the following steps, I’ll demonstrate how to create a simple test repository containing one text file, and how to check out and commit files. If you’re not familiar with Subversion, then this could be a good exercise to learn the basics. Otherwise, you can skip all the test checkouts and commits and just create the repository for your project.
The repository will be a subdirectory in the
repos directory, and will have its group ownership set to
svn (thanks to the
chmod g+s you did earlier). However, that’s not all – you also need to make sure the repository will be group writable, so that the other members of the
svn group will be able to commit files. To do this, set the umask to
$ umask 002
This command sets the new file mode creation mask which controls the default permissions of any new file that you create. The default value is
022 and it corresponds to read/write permissions for the file owner, and read permissions for the group and others. The new value,
002, also gives write permissions to the group, which is just what you need.
Create the repository using the
$ svnadmin create /usr/local/svn/repos/test
And set back the default umask:
$ umask 022
So you now have an empty repository, waiting for you to commit something to it. But, before you do this, you need to check out the current version (i.e., the empty directory) to create a working copy.
$ svn checkout file:///usr/local/svn/repos/test Checked out revision 0.
The working copy has been checked out to a new directory named
test. Go ahead and create a simple “hello world” text file in that directory:
$ cd test $ echo ‘Read Me!’ > readme.txt
Then, add it to version control with the
svn add command:
$ svn add readme.txt A readme.txt
Finally, commit it using
$ svn commit -m “Added a ‘hello world’ text file.” Adding hello.txt Transmitting file data . Committed revision 1.
hello.txt file is now in the repository.
Accessing the Repository with the Svn Protocol
Remote repository access with the svn protocol requires you to use
svnserve, a Subversion server program. Each repository has a
svnserve configuration file (stored in the
conf subdirectory) which controls how the repository can be accessed with
First, create a passwords file that lists the users of the repository and their passwords. This will be a common passwords file for your development team and you will be able to use it with multiple repositories.
$ sudo gedit /usr/local/svn/passwd-team
Here’s a sample passwords file. Each line (except the first one, which is the configuration section name) defines a user name and the corresponding password.
sandeep = somepassword
techiehints = anotherpassword
Since the passwords are stored unencrypted, it’s important that you protect the passwords file by setting the proper permissions. The file should not be readable by anyone except the owner (which is
root), so change its mode to
$ sudo chmod 600 /usr/local/svn/passwd-team
Then, open the
svnserve configuration file in the test repository:
$ gedit /usr/local/svn/repos/test/conf/svnserve.conf
There’s probably some default configuration in the file, but you can just remove everything and enter this:
[general] anon-access = none password-db = /usr/local/svn/passwd-team realm = Team
anon-access = none line denies access to the repository to unauthenticated users (by default, they are allowed read access, so they can do checkouts). The
password-db setting tells svnserve where to look for the passwords file when authenticating users, and the
realm setting defines the name of the authentication realm.
OK, the configuration is ready, so you can now launch
$ sudo svnserve -d –foreground -r /usr/local/svn/repos
The command-line options tell
svnserve to run in daemon mode (
-d) as a foreground process (
--foreground), and to look for repositories in the
repos dir that was created earlier (
-r /usr/local/svn/repos). Normally the program should be running in the background (that’s what daemon processes do), but at this moment you only need to test it, so it’s more convenient to run it in the foreground, where you can easily kill it with
Now, try accessing the repository using the svn protocol. You can try it on another machine over the network, or on the same computer (in another terminal). In the latter case, make sure you’re not doing the checkout in the same directory where the previous test working copy was checked out, because it won’t work – either delete the test directory, or
cd to some other location.
Enter the following
svn checkout command, replacing xxx.xxx.xx.xx with the IP address of your Subversion server (if you’re testing on the same machine, you can use
$ svn checkout svn://xxx.xxx.xx.xx:3690/test –username sandeep
The server will ask you for password:
Authentication realm: <svn://xxx.xxx.xx.xx:3690> Team Password for ‘sandeep’:
Then, it proceeds with the checkout.
A test/hello.txt Checked out revision 1.
And there’s your working copy. Now, check if it works the other way – try modifying the file and committing it back to the repository. Open
hello.txt with a text editor and add some text:
$ cd test
$ gedit hello.txt
How to create new repository & assign users follow simple steps:
svnadmin create /usr/local/svn/repos/my-web
sudo vi /usr/local/svn/web-team
name = password
sudo chmod 600 /usr/local/svn/web-team
sudo vi /usr/local/svn/repos/my-web/conf/svnserve.conf
anon-access = none
password-db = /usr/local/svn/web-team
realm = Team
sudo fuser -k 3690/tcp # kills the previous running instance on 3690
sudo svnserve -d –foreground -r /usr/local/svn/repos &