Installing Mercurial on Unix-like systems

These instructions apply to Linux distributions, MacOS X, and other Unix variants.

Binary packages are available for some Linux distributions, such as Debian. If one is available for your system, that is the easiest way to install it. However, it may not be the latest version. To follow this tutorial, you should probably install from source as described on this page.

Note: some Linux distributions fail to include bits of distutils by default, in which case you'll need python-dev to install.

If your system does not ship with Python, install it first. Version 2.2 or greater is required. You'll also need a C compiler and a 3-way MergeProgram.

Unpacking the source

The necessary first step:

$ tar xvzf mercurial-<ver>.tar.gz
 $ cd mercurial-<ver>

Per-user installation (recommended for now)

To install in your home directory (~/bin and ~/lib, actually), run:

$ python2.3 setup.py install --home=~
 $ export PYTHONPATH=${HOME}/lib/python  # bash syntax, ymmv
 $ export PATH=${HOME}/bin:$PATH         # add these to your .bashrc

On some 64-bit systems (but not all), you'll need to use lib64 instead of lib in PYTHONPATH. The rule of thumb is that if /usr/lib64 exists, use lib64, otherwise lib.

System-wide installation

To install system-wide, you'll need root privileges. It is probably not a good idea to do a system-wide install at the moment, as the project moves so quickly that you'll be endlessly running commands under sudo.

$ python setup.py install   # change python to python2.3 if 2.2 is default

Testing a new install

And finally:

$ hg                                    # test installation, show help

Common problems

If you get complaints about missing modules, you probably haven't set PYTHONPATH correctly.