In today’s article we will show you how to install Subversion on a Linux VPS, and some basic Subversion commands. Subversion, or commonly abbreviated as SVN is an open source software versioning and revision control system. It allows users to maintain current and historical versions of files such as source code, web pages, documents and other electronic data.
First, Install SVN on Linux
In order to install SVN, connect to your Linux VPS via SSH.
If you are using an Ubuntu VPS, update the OS packages and install SVN on your server using the commands below:
sudo apt-get update sudo apt-get install svn
If you are using a CentOS VPS, you can use the following command to update the OS packages and install SVN:
yum update yum install svn
To check the version of SVN installed on your server, use the following command:
# svn --version svn, version 1.7.14 (r1542130)
Create a system user account and switch to that user:
useradd -M someuser
Replace ‘someuser’ with the actual username.
su someuser cd ~
Create a new directory for your project/application/website files:
mkdir -p svn/myapp
Create an SVN repository using the following command:
sudo svnadmin create /home/someuser/svn/myapp
Set the proper file permissions. On Debian based distributions, run:
chown -R www-data:subversion myapp chmod -R g+rws myproject
On RPM based distributions (if using Apache as a web server), run:
chown -R apache:subversion myapp chmod -R g+rws myproject
Create a ‘passwd’ file to the /home/someuser/svn/myapp/conf/passwd directory on your server which contains user authentication details:
sudo htpasswd -c /home/someuser/svn/myapp/conf/passwd someuser
If you want to add additional users, use the same command, but without the ‘-c’ switch to avoid overwriting the passwd file.
Assign permissions to SVN users using the authz file (/home/someuser/svn/myapp/conf/authz):
Create the conceptual groups you want, then add people to it:
[groups] allaccess = someuser someaccess = someuser2
Choose what access they have from both the permissions and project level:
To give read and write permissions to ‘allaccess’ users, add:
[/] @allaccess = rw
To only give read-only access to ‘someaccess’ users to some lower level project, add:
[/someproject] @someaccess = r
In order to copy an unversioned tree of your project/website files and begin tracking in your SVN repository and create intermediate directories, use the following command:
svn import -m "Initial import" local/path/ https://svn.yourdomain.com/path/to/svn/repo/
You can create a single repository for each project/website at some central place where all the history is and which you checkout and commit into.
To create a working copy to another local directory, use:
svn co https://svn.yourdomain.com/path/to/svn/repo/ /local/path/directory2
In order to send changes from your working copy to the repository, use:
svn commit -m "add short info about changes here">
Use ‘svn add /path/file’ command to add a file from the working copy to the repository). File will be added to the repository when you do an svn commit.
To delete a file from the working copy (or repository), use:
svn delete /path/file
and the file will be deleted from the repository after the svn commit command.
To update changes from the repository into a working copy, use:
If there are multiple authors working on the project/website and they have local working copies on multiple machines, always run the ‘svn update’ command before making changes to files available in your working copy. After that, make changes to files, then commit changes to the repository once the files are done being modified.
In order to apply the differences between two sources to a working copy path, use:
To see the differences between the two specific revisions of a file, use:
svn diff -r revision1:revision2 filename