How to Set Up Subversion Version Control in Ubuntu

Ubuntu Set Up Subversion Featured Terminal

When developing a project, you may want to use version control so that you can easily revert a file to the previous revision to fix bugs or restore previously deleted files. In Ubuntu, an easy way to do version control is to set up a Subversion (SVN) server.

Looking for a more popular version control? Check out our beginner’s guide to Git.

What is Subversion?

Subversion is an open source version control software. It allows you to create versions of your code or projects to easily refer to it in the future.

Subversion is similar to Git, another version control software, though their internal workings are different from each other.

Subversion is easier to learn, with fewer commands. You always work on a central Subversion repository when committing changes, which removes confusion between local and remote repositories. However, if you don’t have access to that central repository (if you have no Internet), you can’t make commits. Subversion also lacks some qualit- of-life features that Git has. Also, don’t forget that Git is now far more popular due to the rise of the GitHub and GitLab websites, so you’d get more value out of learning Git instead.

Setting Up Subversion

The first thing to do is install the Subversion software.

  1. Open the Terminal application with the default keyboard shortcut Ctrl + Alt + T.
  2. Update the system:
sudo apt update
Ubuntu Set Up Subversion Sudo Apt Get Update
  1. Install the Apache server:
sudo apt install apache2
Ubuntu Set Up Subversion Sudo Apt Install Apache2
  1. Enter the command to install subversion:
sudo apt install subversion libapache2-mod-svn

Enter Y when prompted to proceed through the installation.

Ubuntu Set Up Subversion Install Libapache2 Mod Svn
  1. Create a directory to hold the server repository:
sudo svnadmin create /var/lib/svn
Ubuntu Set Up Subversion Create Var Lib Svn
  1. Update the access permissions to the repository:
sudo chown -R www-data:www-data /var/lib/svn
sudo chmod 770 -R /var/lib/svn
Ubuntu Set Up Subversion Chmod Permissions

Good to know: find out all of the differences between Apache and Nginx.

Configure Apache for SVN Access

Next, set up your Apache server with SVN.

  1. Open the Apache SVN configuration file:
sudo nano /etc/apache2/mods-available/dav_svn.conf
Ubuntu Set Up Subversion Sudo Gedit Etc Apache2 Mods Available Dav Svn
  1. Find the below lines and remove the ‘#’ in front of them to uncomment:
...
<Location /svn>
DAV svn
SVNPath /var/lib/svn
...
AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /etc/apache2/dav_svn.passwd
...
<LimitExcept GET PROPFIND OPTIONS REPORT>
Require valid-user
</LimitExcept>
...
</Location>
  1. Install utils for Apache:
sudo apt install apache2-utils
Ubuntu Set Up Subversion Apache2 Utils Installation Complete
  1. Create a password for your username:
sudo htpasswd -cm /etc/apache2/dav_svn.passwd yourusername

Remember the password; you’ll need it to run SVN commands later.

Ubuntu Set Up Subversion Sudo Htpasswd
  1. Restart apache with:
sudo /etc/init.d/apache2 restart

Open your browser and go to http://localhost/svn. If you see the following, your installation was successful!

Ubuntu Set Up Subversion Localhost Svn Revision 0

Good to know: Apache also allows you to host a website on your computer. Learn how to prepare Apache for high traffic to your website.

Add Your Project Files to SVN

Now that you have an empty SVN repository, follow these steps to work with it.

  1. Download a working copy of the empty repository with:
svn checkout http://localhost/svn
Ubuntu Set Up Subversion Svn Checkout Localhost
  1. Navigate to the newly created “svn” folder and create or copy your project files to it.
Ubuntu Set Up Subversion Make Files
  1. Use svn add * to select all changed files in your working copy to be committed.
Ubuntu Set Up Subversion Svn Add Asterisk 1
  1. Enter svn commit -m "your commit message" to commit and upload the files added in the previous step to the SVN repository. You’ll need to enter the password you created earlier for this command.
Ubuntu Set Up Subversion Svn Commit
  1. Refresh http://localhost/svn. If you see your new files and an increased “Revision” number, you’ve succeeded!
Ubuntu Set Up Subversion Localhost Revision 1 Success

Image credit: Pexels. All screenshots by Brandon Li.

Is this post useful?
Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Brandon Li

Brandon Li is a technology enthusiast with experience in the software development industry. As a result, he has a lot of knowledge about computers and is passionate about sharing that knowledge with other people. While he has mainly used Windows since early childhood, he also has years of experience working with other major operating systems.