Svn (Subversion) is one of the popular options for maintaining source code versions and revisions on Linux. Here are the steps to install and setup svn repository on Ubuntu Linux with Apache web simple auth.
- First install subversion main package and apache subversion module
sudo apt-get install subversion sudo apt-get install libapache2-svn
- Create a test directory and a file to import into repository. This step can be skipped if you want empty repository.
mkdir mytestproj vi mytestproj/README.txt (with some text)
- Create a home for repositories and create a repository named repo1.
sudo mkdir /svn sudo chown www-data:www-data /svn sudo -u www-data mkdir /svn/repos/ sudo -u www-data svnadmin create /svn/repos/repo1
Here we are making all directories owned by www-data as apache runs as user www-data and should be able to write in these directories.
- Import the test directory into the repository repo1. You can skip this step if you want an empty repository.
sudo -u www-data svn import -m "mytestproj import" mytestproj file:///svn/repos/repo1/mytestproj
- Look at the sample conf file at (/etc/apache2/mods-available/dav_svn.conf). Create your own apache conf file (e.g. /etc/apache/conf.d/my_svn.conf) with the following configuration:
<VirtualHost *:80> ServerName svn.yourserver.com <Location /repos> DAV svn SVNListParentPath on SVNParentPath /svn/repos/ AuthType Basic AuthName "Authorization Realm" AuthUserFile /etc/auth-file-svn Require valid-user </Location> </VirtualHost>
Replace svn.yourserver.com with the appropriate host name. Also make sure that DNS entry exists.
- Create /etc/auth-file-svn using htpasswd
sudo htpasswd -c /etc/auth-file-svn [username]
The username should be desired username for svn checkins. The htpasswd command will ask you for password. The option -c is only needed for first user creation as it will create the file /etc/auth-file-svn.
- Restart apache using
sudo service apache2 restart
and access http://svn.yourserver.com/repos/. You should see the list of repositories as shown below.
Now click on repo1 repository. This corresponding url is http://svn.yourserver.com/repos/repo1/. Here is how it should look:
- To checkout the repository repo1 you can use the following command:
svn co http://svn.yourserver.com/repos/repo1