Last year I took a look at a number of Subversion clients for OS X, finally settling on Versions as my client of choice for my personal coding needs. At the time, I was running a Linux server on some old generic hardware from the days before I drank the Apple Koolaid. After deciding to upgrade my wife’s 17″ iMac with the new i5 27″ model, I realized I could ditch the old Linux hardware and get some great power savings (and hence reduced electricity bill) in the process. The first task I had was moving my SVN repository over from the Linux machine (Ubuntu 9.10) to the iMac running OS X 10.6…and this is how I did it.
All of the SVN application binaries, including the server, already come pre-installed with OS X 10.6, located in the
/usr/bin/ directory, so we just have a few steps to get that running.
- Create a system user for SVN.
- Create a new repository to store your code in.
- Optionally create specific SVN users for submission tracking.
- Configure the server to run automatically at system startup.
Creating an SVN user
While you could easily run the SVN sever with the root user account, for better system security it’s always best to have a dedicated user to run a specific service such as SVN. This limits any possible vulnerabilities in the SVN software from harming the rest of your system; if an exploit is used to end up with a command line ability, the attacker can only damage files belonging to the SVN user.
- Open System Preferences and go the Accounts page.
- Add a new standard user named
svnwith a suitable password.
This user will be included in the OS X login screen when you start your computer. Since there is usually no reason for somebody to log onto the desktop with this user, it can be hidden from the login screen. You can do so by opening the Terminal application and running the following command:
[sourcecode language=”powershell”]sudo defaults write /Library/Preferences/com.apple.loginwindow HiddenUsersList -array-add svn[/sourcecode]
If you ever do want to login as the svn user to the desktop, you can click the new ‘Other’ option that appears in the login screen and manually enter the username. On the other hand, if you don’t want the ‘Other’ option at all you can also disable this by entering the following in a terminal window:
[sourcecode language=”powershell”]sudo defaults write /Library/Preferences/com.apple.loginwindow SHOWOTHERUSERS_MANAGED -bool FALSE[/sourcecode]
You can also delete all the default directories created under the
/Users/svn/ directory if you prefer a neat and tidy file system.
Creating your SVN repository
We now need to create the specific root directory for our repository and create it using the
svnadmin command by launching the OS X Terminal application and entering the following commands.
sudo -u svn mkdir /Users/svn/svnroot
sudo -u svn svnadmin create /Users/svn/svnroot
You can now view the
/Users/svn/svnroot directory and see that new files have been created to form the base of your new repository.
Creating SVN users (optional)
If you are working on your own code and you know without a doubt that nobody else will be accessing your repository, you can skip this step. However it doesn’t hurt to configure a dedicated user now even if it’s just for your sole use, so that code check-ins are properly attributed. To do this we first need to edit the
svnserve.conf file and enable the
passwd file for user authentication. An easy way from the terminal to edit a file is by using the nano text editor:
[sourcecode language=”powershell”]sudo -u svn nano /Users/svn/svnroot/conf/svnserve.conf[/sourcecode]
Remove the # from line 20 so it looks like this:
### Uncomment the line below to use the default password file.
password-db = passwd
If using nano, press Control+X and save your changes. Next edit the
[sourcecode language=”powershell”]sudo -u svn nano /Users/svn/svnroot/conf/passwd[/sourcecode]
Then add the desired usernames and passwords, in my case I’m adding the user ‘bed’ for myself:
### This file is an example password file for svnserve.
### Its format is similar to that of svnserve.conf. As shown in the
### example below it contains one section labelled [users].
### The name and password for each user follow, one account per line.
bed = beds_secret_svn_password
Scheduling the server to start automatically
OS X uses the
launchd subsystem for automatically starting background services. The easiest way to configure
svnserve to run automatically via launchd is by using Lingon. You can grab the latest version from Sourceforge. For more details on using Lingon see this previous article I put together, but for this task we just need to add a new User Daemon:
- Run Lingon, click the New button and select User Daemons.
- Fill out the dialog as follows:
/usr/bin/svnserve --inetd --root=/Users/svn/svnroot/
We now need to click the “Expert” button at the bottom and add the following text under the
So that it looks like this:
Click the save button again and then reboot your computer to give it a test by connecting to localhost or your IP address with your favorite SVN client, ie:
svn://[email protected]. Your SVN server is now ready to be used! The SVN server will only be launched when you first try and use it, so it won’t be taking up any unnecessary resources.
Migrating an existing repository
If you’re like me, and want to migrate an existing repository from another system you can do so easily by skipping the
svnadmin command in step two, and just copy the repository directory from the old system to the new system. I would advise to upgrade your existing repository first to ensure that it is compatible with the version of SVN that comes with OS X (SVN version 1.6.x). Also you’ll want to ensure that the copied file’s owner becomes the new SVN user created in step one.