Posted by Vince Wadhwani on May 28, 2008

Getting subversion going isn't really that hard.. the steps aren't that much different whether you're installing on your local Debian machine or deploying to a server where you'll host lots of projects. Here's how you can set up subversion on Ubuntu's Hardy Heron distribution in a few simple steps.



Step 1: Basics We always start off projects the same way. Update and grab tools.

sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install openssh-server
sudo apt-get install build-essential

Step 2: Subversion This is the easy part and gets you 90% of the way there. Isn't Debian great!?

sudo apt-get install subversion

Step 3: Permissions Here's where you get a bit different when installing on a server for lots of people versus on your local machine. You'll want to create a group called 'subversion' or something similar and add yourself and any others you want to access it to that group.

sudo addgroup subversion
sudo gpasswd -a youruser subversion

Step 4: Permissions continued So far you've created a group and added yourself to it. Next we need to create a place on the server to host your repository and then set permissions there to match what we did in step 3. For this exercise I'll be setting up the repo in /home/svn

sudo mkdir /home/svn
sudo chown root:subversion /home/svn
sudo chmod -R 770 /home/svn

This is where I show my ignorance a bit. I had to reboot in order for the group permissions to take. There's almost definitely a linux command to force that to happen.. in any case, if you don't have fear of reboots then:

sudo reboot

Step 5: Create repository Now we should have access to that /home/svn directory as a regular user assuming you followed Step 3 and rebooted. You'll know in a second because you should be able to type this command without getting an error:

svnadmin create svn/yourproject

If all went well you now have a directory called /home/svn/yourproject. If it didn't and you got a permissions error, go back to Step 3 or in a worse worse case scenario you can chmod -R 777 /home/svn. I highly recommend you avoid that though as it'll give all your local users access to subversion

Step 6: Populate your repository Now that you've created your repository (remember you did *not* use sudo in Step 5!) you can go ahead and import you files into subversion. Assuming you've got a project called myrailsapp in /home/yourusername/ you would type this command to import it:

svn import /home/yourusername/myrailsapp file:///home/svn/yourproject -m "initial import"

Step 7: Check out your code: Now that you've imported your code, it's time to check it out again. Do that by substituting the path to your server and project below.

svn co svn+ssh://myserver.com/home/svn/yourproject

That's all there is to it. If you're using Rails, check the wiki for some tips on using Subversion.