翻译:Subversion on Ubuntu

Do things what you want to do.

This wiki document explains how to setup Subversion alias SVN on Ubuntu. The intended audience is experienced Linux users and system administrators.

If you are new to Subversion, this section provides a quick introduction.
Subversion is an open source version control system. Using Subversion, you can record the history of source files and documents. It manages files and directories over time. A tree of files is placed into a central repository. The repository is much like an ordinary file server, except that it remembers every change ever made to files and directories.

It is assumed that you are aware of how to run Linux commands, edit files, start/stop services in an Ubuntu system. It is also assumed that Ubuntu is running, you have sudo access and you want to use Subversion software.
It is also assumed you have an internet connection.

Scope of this document
To make an SVN repository available to access using the HTTP protocol, you must install & configure web server. Apache 2 is proven to work with SVN. The installation of Apache 2 Webserver is beyond the scope of this document. (See ./ApacheHTTPserver.) However, the configuration of Apache 2 Webserver for SVN is covered in this document.
如果想要可以使用http协议访问一个SVN仓库,你必须安装和配置一个web服务器。Apache 2已经被证实可以与SVN一起工作。安装Apache2 Web服务器的说明不在本文范围之内,请参阅ApacheHTTPserver(https://help.ubuntu.com/community/ApacheHTTPserver)。当然,为SVN配置Apache2服务器是在本文范围之内。
To access an SVN repository using HTTPS protocol, you must install & configure digital certificate in your Apache 2 web server. The installation and configuration of digital certificate is beyond the scope of this document. (See forum/server/apache2/SSL.)

Subversion is already in the main repository, so to install Subversion you can simply install the subversion package (see InstallingSoftware).
If it fails reporting dependencies, please locate the packages and install them. If it reports any other issues, please resolve them. If you cannot resolve the issue, please refer the mailing list archive of those packages.

Server Configuration
This step assumes you have installed above mentioned packages on your system. This section explains how to create SVN repository and access the project.

Create SVN Repository
There are several typical places to put a Subversion repository; most common places are: /srv/svn, /usr/local/svn and /home/svn. For clarity’s sake, we’ll assume we are putting the Subversion repository in /home/svn, and your project’s name is simply ‘myproject’
保存Subversion仓库有几个典型的目录。一般常用的是/srv/svn, /usr/loca/svn和/home/svn。为了表达得更清楚,我们假设Subversion仓库设置在/home/svn,你的项目名称是简单的myproject。
There are also several common ways to set permissions on your repository. However, this area is the most common source of errors in installation, so we will cover it thoroughly. Typically, you should choose to create a new group called ‘subversion’ that will own the repository directory. To do this (see [AddUsersHowto] for details):
1. Choose System > Administration > Users and Groups from your Ubuntu menu.
2. Select the Group tab
3. Click the ‘Add Group’ button
4. Name the group ‘subversion’
5.Add yourself and www-data (the Apache user) as users to this group
(Note: in order to see www-data you may need to see FixShowAllUsers)
6. Select ‘OK’ to commit your changes and exit the app.

You have to logout and login again before you are a member of the subversion group, and can do check ins.

Now issue the following commands:

[code language=”bash”]
$ sudo mkdir /home/svn
$ cd /home/svn
$ sudo mkdir myproject

The SVN repository can be created using the following command:

$ sudo svnadmin create /home/svn/myproject

And use the following commands to correct file permissions:
[code language=”bash”]
$ cd /home/svn
$ sudo chown -R www-data:subversion myproject
$ sudo chmod -R g+rws myproject
The last command sets gid for proper permissions on all new files added to your Subversion repository.

If you want to use WebDAV as an access method described below, repeat the chmod -R g+rws myproject command again. This is because svnadmin will create directories and files without group write access. This is no problem for read only access or using the custom svn protocol but when Apache tries to commit changes to the repository linux will deny it access. Also the owner and group are set as root. This can be changed by repeating the chown and chgrp commands listed above.
如果你想如下面描述一样使用WebDAV作为一种访问方式,需要再重复一下chmod -R g+rws myproject命令。这是因为svnadmin将创建目录和文件,但是没有组的写入权限。这对于只读的访问或者使用定制的svn协议是没有任何问题的,但是Apache会试图向仓库提交改变,这时Linux将拒绝它的访问。同时,所有者和组都设置成了root用户。这些都可以通过下面重复的chown和chgrp命令来改变。

Access Methods
Subversion repositories can be accessed (checkout) through many different methods-on local disk, or through various network protocols. A repository location, however, is always a URL. The table describes how different URL schemas map to the available access methods.

Schema Access Method
file:/// direct repository access (on local disk)
http:// Access via WebDAV protocol to Subversion-aware Apache 2 web server
https:// Same as http://, but with SSL encryption
svn:// Access via custom protocol to an svnserve server
svn+ssh:// Same as svn://, but through an SSH tunnel

In this section, we will see how to configure SVN for all these access methods. Here, we cover the basics. For more advanced usage details, you are always recommended to refer the svn book.

Direct repository access (file://)
This is the simplest of all access methods. It does not require any SVN server process to be running. This access method is used to access SVN from the same machine. The syntax is as follows:
[code language=”bash”]
$ svn co file:///home/svn/myproject
[code language=”bash”]
$ svn co file://localhost/home/svn/myproject
NOTE: Please note, if you do not specify the hostname, you must use three forward slashes (///). If you specify the hostname, you must use two forward slashes (//).

The repository permission is dependant on filesystem permission. If the user has read/write permission, he can checkout/commit the changes to the repository. If you set permissions as above, you can give new users the ability to checkout/commit by simply adding them to the Subversion group you added above.

Access via WebDAV protocol (http://)
To access the SVN repository via WebDAV protocol, you must configure your Apache 2 web server.

First install the following package libapache2-svn (see InstallingSoftware).
首先要安装下面的包:libapache2-svn(见安装软件,注:[code language=”bash”]sudo apt-get install libapache2-svn[/code])

You must add the following snippet in your /etc/apache2/mods-available/dav_svn.conf file:
[code language=”xml”]

DAV svn
SVNPath /home/svn/myproject
AuthType Basic
AuthName “myproject subversion repository”
AuthUserFile /etc/subversion/passwd Require valid-user

NOTE: The above configuration assumes that all Subversion repositories are available under /home/svn directory.

TIP: If you want the ability to browse all projects on this repository by going to the root url (http://www.serveraddress.com/svn) use the following in dav_svn.conf instead of the previous listing:
[code language=”xml”]

DAV svn
SVNParentPath /home/svn
SVNListParentPath On
AuthType Basic
AuthName “Subversion Repository”
AuthUserFile /etc/subversion/passwd Require valid-user


NOTE: To limit any connection to the SVN-Server (private SVN), remove the lines and .

Alternatively, you can allow svn access on a per-site basis. This is done by adding the previous snippet into the desired site configuration file located in /etc/apache2/sites-available/ directory.

Once you add the above lines, you must restart apache2 web server. To restart apache2 web server, you can run the following command:
[code language=”bash”]
sudo /etc/init.d/apache2 restart

Next, you must create /etc/subversion/passwd file. This file contains user authentication details.

If you have just installed SVN, the passwd file will not yet exist and needs to be created using the “-c” switch. Adding any users after that should be done without the “-c” switch to avoid overwriting the passwd file.

To add the first entry, ie.. to add the first user, you can run the following command:

[code language=”bash”]
sudo htpasswd -c /etc/subversion/passwd user_name

It prompts you to enter the password. Once you enter the password, the user is added.

To add more users after that, you can run the following command:

[code language=”bash”]
sudo htpasswd /etc/subversion/passwd second_user_name

If you are uncertain whether the passwd file exists, running the command below will tell you whether the file already exists:

[code language=”bash”]
cat /etc/subversion/passwd

Now, to access the repository you can run the following command:
[code language=”bash”]
$ svn co http://hostname/svn/myproject myproject –username user_name

It prompts you to enter the password. You must enter the password configured using htpasswd2 command. Once it is authenticated the project is checked out. If you encounter access denied, please remember to logout and login again for your memebership of the subversion user-group to take effect.

WARNING: The password is transmitted as plain text. If you are worried about password snooping, you are advised to use SSL encryption. For details, please refer next section.

Access via WebDAV protocol with SSL encryption (https://)
Accessing SVN repository via WebDAV protocol with SSL encryption (https://) is similar to http:// except you must install and configure the digital certificate in your Apache 2 web server.

You can install a digital certificate issued by Signing authority like Verisign. Alternatively, you can install your own self signed certificate.

This step assumes you have installed and configured digital certificate in your Apache 2 web server. Now to access SVN repository please refer the above section. You must use https:// to access the SVN repository.

Access via custom protocol (svn://)
Once the SVN repository is created, you can configure the access control. You can edit /home/svn/myproject/conf/svnserve.conf file to configure the access control.

NOTE: svnserve.conf is sensitive to whitespace, be sure not to leave any whitespace at the start of a line or it will not be able to read the file.

For example, to setup authentication you can uncomment the following lines in the configuration file:

[code language=”bash”]
# [general]
# password-db = passwd

After uncommenting the above lines, you can maintain the user list in passwd file. So, edit the file passwd in the same directory and add new user. The syntax is as follows:

[code language=”bash”]
username = password

For more details, please refer the file.

Now, to access SVN via svn:// custom protocol either from the same machine or different machine, you can run svnserver using svnserve command. The syntax is as follows:

[code language=”bash”]
$ svnserve -d –foreground -r /home/svn
# -d — daemon mode
# –foreground — run in foreground (useful for debugging)
# -r — root of directory to serve

For more usage details, please refer,
[code language=”bash”]
$ svnserve –help

Once you run this command, SVN starts listening on default port (3690). To access the project repository, you must run the following command:

[code language=”bash”]
$ svn co svn://hostname/myproject myproject –username user_name

Based on server configuration, it prompts for password. Once it is authenticated, it checks out the code from SVN repository.

To synchronize the project repository with the local copy, you can run update sub-command. The syntax is as follows:
[code language=”bash”]
$ cd project_dir
$ svn update

For more details about using each SVN sub-command, you can refer the manual. For example, to learn more about co (checkout) command, please run:
想要了解每一个SVN的子命令,你可以参考用户手册。例如,想要了解co(checkout)命令,请运行 :

[code language=”bash”]
$ svn help co

Start svnserve at bootup

One can start the svnserve daemon at bootup using an initd script. Look at Michał Wojciechowski Blog post for instructions and a good initd script for svnserve.
用户可以使用initd脚本在系统起动时开始svnserve守护进程。 可以看看Michał Wojciechowski博客上的安装指南和svnserve的不错的initd脚本。

Access via custom protocol with SSL encryption (svn+ssh://)

It is not necessary to run the SVN server (svnserve) in order to access SVN repositories on a remote machine using this method. However, it is assumed that the SSH server is running in the remote machine with the repository and it is allowing incoming connections. To confirm, please try to login to that machine using ssh. If you can login, then everything is perfect. If you cannot login, please address it before continuing further.
如果用这种方式要访问另一台机器上的SVN仓库,其实无需运行 SVN服务器(svnserve)。然而,它要假设SSH服务器已经运行,并且允许进来的访问。为了确定这些,请使用ssh登录那台机器。如果你可以登录,所有事情都非常完美。

The svn+ssh:// protocol is used for accessing SVN repositories with SSL encryption for secure data transfer. To access a repository using this method, run the following command:

[code language=”bash”]
$ svn co svn+ssh://hostname/home/svn/myproject myproject –username user_name

NOTE: You must use full path (/home/svn/myproject) to access an SVN repository using this method.

Based on the SSH server configuration, it prompts for password. You must enter the password you use to login via ssh. Once it is authenticated, it checks out the code from SVN repository.

You can also refer the SVN book for details about the svn+ssh:// protocol.

References 参考
Setting up Apache on Ubuntu 在Ubuntu中安装配置Apache
SVN Home page SVN主页
SVN Book SVN图书
Apache 2 Documentation Apache 2文档

非常棒的连续剧。Don’t do that even if it so long ago.
Cold Case

《翻译:Subversion on Ubuntu》上有1条评论


电子邮件地址不会被公开。 必填项已用*标注