Subversion is an open-source version control system. It helps you keep track of a collection of files and folders. Any time you change, add or delete a file or folder that you manage with Subversion, you commit these changes to your Subversion repository, which creates a new revision in your repository reflecting these changes. You can always go back, look at and get the contents of previous revisions.
This article will help you for step by step setup of Subversion (svn) server on Ubuntu 18.04 LTS & 16.04 LTS systems.
Step 1 – Install Apache
First of all, you need to install the Apache webserver to access the svn server using HTTP URLs. Skip this step if you already have Apache web server on your system.
sudo apt-get update sudo apt-get install apache2
Step 2 – Install SVN Server
Use the following command to install subversion packages and their dependencies. Also, install svn module for Apache libapache2-mod-svn packages on your system.
sudo apt-get install subversion libapache2-mod-svn libapache2-svn libsvn-dev
After installation, enable required Apache modules and restart Apache service.
sudo a2enmod dav dav_svn sudo service apache2 restart
Step 3 – Create First SVN Repository
Use the following commands to create your first svn repository with name myrepo. Also, set the required permissions on newly created directories.
sudo mkdir -p /var/lib/svn/ sudo svnadmin create /var/lib/svn/myrepo sudo chown -R www-data:www-data /var/lib/svn sudo chmod -R 775 /var/lib/svn
Step 4 – Create Users for Subversion
Now create first svn user in /etc/apache2/dav_svn.passwd file. These users will use for authentication of svn repositories for checkout, commit processes.
sudo touch /etc/apache2/dav_svn.passwd sudo htpasswd -m /etc/apache2/dav_svn.passwd admin
To create additional users, use following commands.
sudo htpasswd -m /etc/apache2/dav_svn.passwd user1 sudo htpasswd -m /etc/apache2/dav_svn.passwd user2
Step 5 – Configure Apache with Subversion
Subversion Apache module package creates an configuration file /etc/apache2/mods-enabled/dav_svn.conf. You just need to make necessary changes to it.
sudo vi /etc/apache2/mods-enabled/dav_svn.conf
Alias /svn /var/lib/svn <Location /svn> DAV svn SVNParentPath /var/lib/svn AuthType Basic AuthName "Subversion Repository" AuthUserFile /etc/apache2/dav_svn.passwd Require valid-user </Location>
Save the file and restart the Apache service to apply the new configuration.
sudo service apache2 restart
Step 6 – Access Repository in Browser
Use HTTP URLs to access your repository in the browser. It will prompt for authentication. Use login credentials created in Step 5. Change example.com with your system hostname, domain name or IP address.
http://example.com/svn/myrepo/
47 Comments
This tutorial is great, but it has some mistakes.
STEP 2: Debian 11+ will not find libapache2-svn library, because libapache2-mod-svn already it have
so it should look like this
“sudo apt-get install subversion libapache2-mod-svn libsvn-dev”
STEP 5: Don’t need “Alias /svn /var/lib/svn”, programs like Eclipse will not accept this SVN with this alias and will get always redirects.
Hi,
I need to create two folders with a subfolder each to have the following access
http://IP ADRESS/folder1/subfolder1
http://IPADRESS/folder2/subfolder2
my setup is compiled this way, and i can’t recompile
How should I proceed?
how to checkout sir…..
you need to sudo apt-get install libapache-2-mod-svn
If you want to delete a created user, use command: sudo htpasswd -D /etc/apache2/dav_svn.passwd created_user_name
Many thanks and I did exactly the way you did and it worked fine. I could connect to repository, but could not create folder to synch my projects. It was giving me this error: Repository permanently moved to ….
So I found another piece somewhere else and changed the part for
sudo vi /etc/apache2/mods-enabled/dav_svn.conf
to this:
ServerName Azarbod
DAV svn
SVNParentPath /var/lib/svn
AuthType Basic
AuthName “Subversion Repository”
AuthUserFile /etc/apache2/dav_svn.passwd
Require valid-user
It now works.
Hi, i am facing some issue & i want to know how to commit code from my End-user, Error as below
This XML file does not appear to have any style information associated with it. The document tree is shown below.
I’m getting this error while trying to restart apache
Job for apache2.service failed because the control process exited with error code.
See “systemctl status apache2.service” and “journalctl -xe” for details.
Can you please help?
Amazing was looking for svn setup , hard to find tuts on svn
It’s true that i can’t locate my repository in external device like NAS or CLOUD?, I was reading that i could have problems… thanks!
Hi
I am tring to install SVN on Ubuntu 18.04.
During restart I am getting this
sudo service apache2 restart
Job for apache2.service failed because the control process exited with error code.
See “systemctl status apache2.service” and “journalctl -xe” for details.
Please help.
What is the output of ‘systemctl status apache2.service’?
I’ve had the same problem as Rita. And here’s what I got when I ran systemctl status apache2.service:
apache2.service – The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Drop-In: /lib/systemd/system/apache2.service.d
└─apache2-systemd.conf
Active: failed (Result: exit-code) since Tue 2019-12-17 11:19:54 UTC; 8min ago
Process: 7570 ExecStart=/usr/sbin/apachectl start (code=exited, status=1/FAILURE)
how does one edit the conf file in step 5?
Hi Joel, Are you facing any issue with the configuration file edition?
It does not work and I don’t understand why, I followed instruction carefully 2 times. Everything seems smooth but when i try to log in it continue to ask the login, and goes nowhere. I also restarted apache2 several times and updated passwords but…nothing to do. How can I understand my errors?
Hi Dario,
I have again tested the tutorial and it works fine for me. What issue are you getting?
Thanks Rahul, I’ve followed the procedure and everthing is just fine, then when i go to http://myip/vpn/repo (with the right address) I get the autentication required, but when I login continue to ask me the name and password and goes nowhere
You may have had the same issue I did – I added several users when doing the add users step above – but I kept using the same initial command that had the “-cm” in it. the “c” creates the file, wiping any entries from before so you only end up with the last user you added. If you also added multiple users, try logging in with the last user you added and see if that works. Solution is to make sure you are using just the “htpasswd -m” option for all users after the first user (and not “htpasswd -cm”). Hope this helps someone!
I have created user with : sudo htpasswd -m /etc/apache2/dav_svn.passwd user1
So how user1 can change the password to access the repo.
You can simply run the same command to update the password.
sudo htpasswd -m /etc/apache2/dav_svn.passwd user1
FYI: Do not use -c while updating passsword. This will recreate the existing dav_svn.passwd file.
I can confirm it is required to disable the Alias rule
in dav_svn.conf
#Alias /svn /var/lib/svn
Otherwise you’ll get:
“Repository moved permanently svn” error message.
I have to remark the line of
“Alias /svn /var/lib/svn”
in dav_svn.conf, for my import action to work, without
“Repository moved permanently svn” error message.
FYI.
sudo a2enmod dav_svn
ERROR: Module dav_svn does not exist!
Help please
Hi,
I follow each and every step in tutorial and tried to access SVN repository with
“http://localhost/svn/myrepo”
The requested URL /svn/myrepo was not found on this server.
me too
Are you using the same directory structure and configuration as in article.
Also, Please confirm, what is showing on http://localhost/svn/ url?
You need to restart apache server
Hi there, when I followed the guide I too had this problem. The article above is correct, but the default SVN config file has some extra lines that can get you into trouble and cause this problem – as I found myself.
Turns out I used the wrong directive in the config file. If you are setting up multiple repos (as per this article) and use “SVNPath” you get these errors messages. That’s because you have gone and created “myrepo1”, “myrepo2”, “myrepo3” … etc and the “SVNPath” directive is expecting a single repo at /var/lib/svn.
You need to use the “SVNParentPath” directive to tell SVN that there are multiple repos sitting under this path.
So my config file now uses this (as per the article above) and it works:
SVNParentPath /var/lib/svn
Rahul,
Can you please help me, Why we use SVN? and what the steps to configure SVN in redhat.
Regards
Ashanta
what is my host name, domain name or IP address.
how do i know that
You can use following commands to get the hostname of your system or ip address.
$ hostname
$ ifconfig
good – thanks.
Alias /svn /var/lib/svn is redundant and it will cause an error “svn: E195019: Redirect cycle detected for URL ‘http://172.18.19.182/svn/heliteqRepo'”
Thanks, it helps
How to Store my commie file
Hi, Rahul,
I followed your tutorial to the end inside a VirtualBox, but when I try to execute the ‘svn list’ command it returns the error ‘E195019: Redirect cycle detected for url’.
Do you know how to fix this?
Hi,
I removed the Alias /svn /var/lib/svn line from the /etc/apache2/mods-enabled/dav_svn.conf file in Step 3. and the problem was solved.
Regarding Step 3…
I found that in order to see the directory contents in the browser I had to add the following line to the config file in addition to those shown:
SVNListParentPath On
See: http://svnbook.red-bean.com/nightly/en/svn.serverconfig.httpd.html#svn.serverconfig.httpd.extra.browsing.reposlisting
I also found that these changes do not take effect until you restart Apache again by running:
sudo service apache2 restart
Otherwise, this was very helpful. I used these instructions to get started on a browser based Subversion client (https://github.com/Pamblam/iLoveLAMP). Thanks for the article.
The following line:
“`
AuthUserFile Require valid-user
“`
Must only be:
“`
Require valid-user
“`
Thanks, Wayan
The article has been updated.
Hi Rahul,
I tried same config in ubuntu 16.10 and got the following errors.
svn@svn-HP-ProBook-4510s:/$ sudo a2enmod dav_svn
ERROR: Module dav_svn does not exist!
I’d fixed this error.
Please see this solution
https://kcode.de/wordpress/1734-fixing-libapache2-svn-error-module-dav_svn-does-not-exist
————
Well, just create the folders
/etc/apache2/mods-available/dav_svn.conf
/etc/apache2/mods-available/dav_svn.load
————
Hello, now i wish to add an extra repository like “Music” and its view in browser repository, what is the process ?
Use below command
$ sudo svnadmin create /var/lib/svn/Music
Now access in browser like: http://localhost/svn/Music
I was getting an authentication error until I add “Require valid-user”, for example:
Alias /svn /var/lib/svn
DAV svn
SVNParentPath /var/lib/svn
SVNListParentPath On
AuthType Basic
AuthName “Subversion”
AuthUserFile /etc/apache2/dav_svn.passwd
Require valid-user
Thanks Oscar,
The tutorial has been updated.