Installing Mercurial on Linux

Update: I’ve updated this post to focus on the steps to take in order to get mercurial working on your system, and some rough guidelines.

To install, use your installation/package manager. In Ubuntu, run:

sudo apt-get install mercurial

Now you need to set permissions. Inside your home directory, ~/, you can set up your “hgrc” (mercurial configuration file) with your username and default email address. Note that you must create and edit this file as the owner of ~/, not as root, because mercurial will only trust files that you created.  So open or create the file ~/.hgrc. Then enter the following lines:


username = My Name <>

with your name and email. Now you should be able to check out and use repositories.

Note that if you get errors about untrusted users (for example, mercurial ignores anything from “untrusted user root”, the only fix may be to edit your systems hgrc file to trust those users. The file is called /etc/mercurial/hgrc and you should add these lines to it:


users = root

Or any other users you wish to trust.

Using Mercurial

I won’t cover how to set up a Mercurial repository, because I didn’t — I just used bitbucket. To start out with a repository located at some url, use cd to navigate to the directory you want to use, then use hg clone to get a copy of a project. For example:

cd ~/my-documents/my-projects/
hg clone

Or wherever it is. Now you’re ready to start developing!  If you create a new file or folder, you must add it to the project:

hg add *

Sending and receiving updates is a two-step process. To finalize all the changes and additions you’ve made, you must commit the changes. To send that final version to the repository, you must push it.

hg commit -m 'Made some changes'
hg push

Conversely, to get the newest version from the repository, you must pull it. To change your working copy to incorporate this new version, you must updateit.

hg pull
hg update

That’s the gist of it.