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.

Advertisement

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/

Install Svn Server 1

Thank You for using this article. Read our next article How to Backup and Restore SVN Repository in Linux.

Share.

46 Comments

  1. If you want to delete a created user, use command: sudo htpasswd -D /etc/apache2/dav_svn.passwd created_user_name

  2. 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.

  3. 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.

  4. 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?

  5. 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!

  6. 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.

      • 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)

  7. 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?

      • 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!

  8. 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.

  9. 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.

  10. 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.

  11. 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.

    • LazyCodeMonkey on

      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

  12. 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'”

  13. Bruno Romeiro on

    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.

  14. 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.

  15. 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!

  16. Hello, now i wish to add an extra repository like “Music” and its view in browser repository, what is the process ?

  17. 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

Exit mobile version