64

I am kind of new to both, Mercurial and Ubuntu.

I seem to have awkwardly installed a few other software packages already, so I wanted to see how others would go about doing this.

Should I use the apt-get command? If so, how would I use it in this case? Where is the best place to install Mercurial on my file system, and how do I make it part of my shell (I am thinking svn-ish) so I can properly check things in and update?

Thanks, Alex

2
  • 3
    You should always use apt-get or whatever is the native package manager of the current platform unless you can't or have a very good reason to do otherwise. Commented Apr 11, 2011 at 20:54
  • 4
    belongs on Ask Ubuntu in my opinion. Commented Apr 12, 2011 at 16:51

8 Answers 8

117

Just use:

sudo apt-get install mercurial 

It should install it in the default folder and update your environment variables correctly. then you should be able to use 'hg' from the command line, just like svn, although Hg is a much better source control tool.

Sign up to request clarification or add additional context in comments.

3 Comments

Somehow amazingly enough that worked lol. Now how do I configure/use it? :)
@Genadinik: The beautiful thing about package managements already does everything for you. You just go and use the hg command from a shell.
configure it? if you want to start a repo use 'hg init'. If you want to customize the repository edit hgrc file.
64

NEW ANSWER

Previously I was pointing to TortoiseHG PPA, which also contained Mercurial. For now (year 2015) the more recent version of Mercurial is in another PPA, specific for Mercurial only.

Important note: this version is incompatible with TortoiseHG, and Tortoise will be REMOVED, if you install the more recent Mercurial!

If you don't care of Tortoise and just want more recent Mercurial package, use next command to install:

sudo add-apt-repository -y ppa:mercurial-ppa/releases sudo apt-get update sudo apt-get install -y mercurial 

However, this won't give you the absolutely latest version either. To enjoy the latest version, you may want to install it via PIP:

sudo apt-get install -y python-pip python-dev sudo pip install mercurial --upgrade 

This would give you the very latest version (3.6.2 vs 3.3.2 from the PPA). Seems this one is also not compatible with TortoiseHG from the repos.


OLD ANSWER

Though available from default repos, the version there is outdated. At the time of writing: 2.2.2 vs 2.5.2. So I would recommend to use the PPA:

sudo add-apt-repository -y ppa:tortoisehg-ppa/releases sudo apt-get update sudo apt-get install mercurial tortoisehg 

TortoiseHG is not required, but is recommended.

5 Comments

For Ubuntu 10.04 this gave me a much newer version than the default package.
On 12.04 this gave 2.8.2 instead of 2.0.2!! Huge difference!
On 20.04 and just running sudo apt install mercurial without adding PPAs installed v5.3.1
This is much more useful than the accepted answer! On Xenial, this gave me the most recent version 5.5.1 instead of a hugely outdated version 3.1.3.
This is unfortunately super old now and not useful on any recent version of Ubuntu :( I wish it wasn't so hard to install later versions of things on Linux. On Windows I just download whichever installer I want, but on Linux I don't get to choose unless I want to build from source, which is a pain.
12

Yeah you can install it by just

sudo apt-get install mercurial 

but for me it gave very old version (2.0.2). You can check this by hg version. To get the newer version you can do

sudo apt-get install python-setuptools python-dev build-essential sudo easy_install -U mercurial 

Now I have 3.0.1 version

aniket@ubuntu:~$ hg version Mercurial Distributed SCM (version 3.0.1) (see http://mercurial.selenic.com for more information) Copyright (C) 2005-2014 Matt Mackall and others This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 

More details : Installing Mercurial on Linux

PS: Above link goes to my personal blog which has additional details.

1 Comment

I just wanted to say that "apt-get install mercurial" wasn't updating to the latest version (even though it said it was doing so). This solution finally worked. Thank you.
9

Mercurial is available from the Universe repositories. Enable that repository in USC if it's not already enabled. Then just type the following into a terminal.

sudo apt-get install mercurial 

The configuration file is saved in /etc/mercurial/hgrc You can configure mercurial by editing that file. To open that file in gedit type the following command

sudo gksudo gedit /etc/mercurial/hgrc 

Comments

6

If you are using an older version of Ubuntu (12.04 perhaps?), use the Mercurial PPA.

sudo add-apt-repository ppa:mercurial-ppa/releases sudo apt-get update sudo apt-get install mercurial 

As of this writing, this installs mercurial 3.0.1 on Ubuntu 12.04 for example.

Comments

3

just to let everyone know,
sudo apt-get install mercurial
is delivering version 3.0.1 (latest as the time of writing this post)
so no need to try other stuff as this is everything you'll need.

3 Comments

in what version of ubuntu?
lubuntu 14.04, I believe in ubuntu should be the same.
It doesn't seem to be true for regular Ubuntu 14.04.
2

The Mercurial version in the Ubuntu repository is relatively old. I tried to use the PPA, to get more recent version. But Ubuntu complains that "The repository ... does not have a Release file" and disables it. Then I used alternative way to install latest Mercurial version:

sudo pip3 install mercurial --upgrade 

Comments

0

pip3 approach does not always work because it complains on clashing with system packages, and there is no easy way out of that.

Instead, pipx utility performs isolated installation of Python packages to the user directory. But it can also be instructed to install a package globally by specifying --global option:

apt-get install pipx pipx install mercurial --global 

Or in a Dockerfile:

# Install pipx RUN DEBIAN_FRONTEND=noninteractive apt-get install -y pipx # Bootstrap pipx to the latest version. RUN pipx install pipx RUN apt-get remove -y pipx RUN ~/.local/bin/pipx install pipx --global RUN pipx uninstall pipx # Install Mercurial RUN pipx install mercurial --global 

Note that Dockerfile does "bootstrapping" of pipx by installing the latest pipx version by running the existing pipx that was previously installed by the OS package manager (apt). This bootstrapping is needed in order to get access to the --global option, as older versions of pipx did not support it.

After that, the newest pipx is used to install Mercurial in a system-wide fashion, so it can be used by other apps and scripts in the Docker image.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.