Linux and CVS


Staff member
Oct 27, 2011
Reaction score
Using Version Control Systems

If you're going to be programming, especially in collaboration with other people, nothing beats a version control system for keeping track of the codebase and the changes you're making. Don't think you have to be involved with some big project either using C or some other heavy duty language. You can use a version control system for anything that involves saving frequently changed files on a computer. It could be a simple website or even that novel that you're writing.


The most widely used version control system for Linux is CVS. CVS comes with all major distributions and is easily installed as part of the standard installation procedure.

Setting up a CVS server

If you're thinking of working on a project, even if you're going to be the only developer, it's worth your while to set up a version control system like CVS. First, you'll need to choose where you'll be putting your files. This is going to be your repository. Though a repository can be part of an existing home user's directory, I think it's a good idea to create a new, distinct user for a CVS repository. For this example, we'll create the user 'devel'. Once 'devel' exists and has its own home directory, you can now create the repository. Log in as the user 'devel' and issue the following command:

cvs -d /home/devel/ init
You will now see a directory in /home/devel called 'cvsroot'. Inside this directory, create a directory. For this example, we'll call it 'projects'. Inside the directory projects, we'll create our first file. Using you favorite text editor, just create a file with something in it. If you want to type actual source code, then fine. But anything will do. Now that you've got your first directory and your first source code file, it's time to import this directory into your repository. From now on, it will be your central repository for source code. Issue the following command:

cvs import -m "first file" projects devel start
The -m option is for leaving a message. This will appear in our history logs. As we'll see further along, it's good to leave messages when changes are made. This will aid in understanding what's going on during the development process. The rest corresponds to our first directory, the user name and you must finish with start.
Before we do anything else, we should add users to devel's group in /etc/group. This will permit us to connect to use the CVS repository. Your entry for devel should look like this:

That would allow the user 'mike' to access the repository. To actually use the repository, we need to do one more thing. You need to add this to the end of your .bashrc file:
First, change the cvsroot server-name to the actual server you're using. You'll notice the CVSEDITOR variable. What this does is to use emacs as the default editor for messages. For example, instead of typing: -m "message", you can omit the message part and it will automatically fire up emacs. Now, I happen to have a preference for emacs as an editor. You can use the editor that you like.

Now you're ready to use the CVS repository on your server. First, let's get the project. Type this into a terminal:

cvs -q get projects
You will be asked for your password. The project will be whisked over via SSH. Now you're ready to add to it.

Using CVS

Here is a list of the most frequently used commands that you'll be using in your day to day work with CVS

cvs add file
This is used to add a file. If you're adding a binary file, like an executable or an image, then you should use:

cvs add -kb file
This sends your changes to the repository.

cvs update file
This is for committing the file to the repository. As I mentioned above, if you'd like, you can omit the "message" part and your preferred text editor will be used to write the message.This needs to be used after 'add' or 'update'.

cvs commit -m "message" file
This will show you the status of the file. If it's locally modified, up-to-date with the repository or if it doesn't exist - this command will show you.
You might also want to look into a graphical tool like cervisia that works quite well and has a lot of options. If you're not good at religiously checking in your changes to the repository, cervisia will help you track down the modified files more easily.
cvs status file

Members online