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.
- Open the Terminal application with the default keyboard shortcut Ctrl + Alt + T.
- Update the system:
sudo apt update
- Install the Apache server:
sudo apt install apache2
- Enter the command to install subversion:
sudo apt install subversion libapache2-mod-svn
Enter Y
when prompted to proceed through the installation.
- Create a directory to hold the server repository:
sudo svnadmin create /var/lib/svn
- Update the access permissions to the repository:
sudo chown -R www-data:www-data /var/lib/svn sudo chmod 770 -R /var/lib/svn
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.
- Open the Apache SVN configuration file:
sudo nano /etc/apache2/mods-available/dav_svn.conf
- 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>
- Install utils for Apache:
sudo apt install apache2-utils
- 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.
- 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!
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.
- Download a working copy of the empty repository with:
svn checkout http://localhost/svn
- Navigate to the newly created “svn” folder and create or copy your project files to it.
- Use
svn add *
to select all changed files in your working copy to be committed.
- 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.
- Refresh http://localhost/svn. If you see your new files and an increased “Revision” number, you’ve succeeded!
Image credit: Pexels. All screenshots by Brandon Li.
Our latest tutorials delivered straight to your inbox