113

Here is my case:

I am using Ubuntu 10.04 (Lucid Lynx). The system's default Python is v2.6.5, but I need Python v2.7. So I downloaded the source from python.org and tried to install it.

The first time I installed it, I ran:

cd Python2.7.4
./configure --prefix=/usr
make
su root
make install

This installs Python 2.7 to my system. It will create a link, "python", in /usr/bin linking to python2.7 also in /usr/bin. So when I type >python, the system will start Python 2.7.4 for me just like when I type >python2.7.

But when I install this way:

cd Python2.7.4
./configure --prefix=/usr
make
su root
make altinstall

The link "python" in /usr/bin still exists and links to python2.6 which is the default system version. Of course, I can remove it and create a new soft link linking to python2.7.

What is the difference between the command "make install" and "make altinstall", except for the link in /usr/bin?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
qiuhan1989
  • 1,523
  • 2
  • 13
  • 18

2 Answers2

173

TLDR: altinstall skips creating the python link and the manual pages links, install will hide the system binaries and manual pages.

Let's take a look at the generated Makefile!

First, the install target:

install:         altinstall bininstall maninstall

It does everything altinstall does, along with bininstall and maninstall

Here's bininstall; it just creates the python and other symbolic links.

# Install the interpreter by creating a symlink chain:
#  $(PYTHON) -> python2 -> python$(VERSION))
# Also create equivalent chains for other installed files
bininstall:     altbininstall
        -if test -f $(DESTDIR)$(BINDIR)/$(PYTHON) -o -h $(DESTDIR)$(BINDIR)/$(PYTHON); \
        then rm -f $(DESTDIR)$(BINDIR)/$(PYTHON); \
        else true; \
        fi
        (cd $(DESTDIR)$(BINDIR); $(LN) -s python2$(EXE) $(PYTHON))
        -rm -f $(DESTDIR)$(BINDIR)/python2$(EXE)
        (cd $(DESTDIR)$(BINDIR); $(LN) -s python$(VERSION)$(EXE) python2$(EXE))
        ... (More links created)

And here's maninstall, it just creates "unversioned" links to the Python manual pages.

# Install the unversioned manual pages
maninstall:     altmaninstall
        -rm -f $(DESTDIR)$(MANDIR)/man1/python2.1
        (cd $(DESTDIR)$(MANDIR)/man1; $(LN) -s python$(VERSION).1 python2.1)
        -rm -f $(DESTDIR)$(MANDIR)/man1/python.1
        (cd $(DESTDIR)$(MANDIR)/man1; $(LN) -s python2.1 python.1)
TheMechanic
  • 820
  • 1
  • 8
  • 23
Collin
  • 11,977
  • 2
  • 46
  • 60
  • Ok, this answer is good and I understand. Thank you. I have a further question that is you just mentioned the "maininstall" is used to create the manual pages. What do you mean for "manual page"? The result of command "man python"? – qiuhan1989 Apr 15 '13 at 15:21
  • 3
    Exactly, the `man` program looks for installed manual pages when it is run. To look at the 2.7 man pages after running `altinstall`, you'll need to use `man python2.7` – Collin Apr 15 '13 at 15:22
  • 4
    Specific guidance about using `make altinstall` over `make install` can be found in [Python's UNIX documentation](https://docs.python.org/3/using/unix.html?highlight=altinstall#building-python). – Brett Cannon Nov 30 '18 at 01:48
  • 32
    Awesome answer, but the TLDR should be at the top. – Ryuu Jan 10 '19 at 05:38
  • 7
    The TLDR si conventionally at the end. – Reda Drissi Jan 17 '19 at 13:26
  • I faced [this problem regarding lsb_release](https://stackoverflow.com/questions/44967202/pip-is-showing-error-lsb-release-a-returned-non-zero-exit-status-1). I fixed it by using altinstall - thank you very much! – Meiswjn Nov 11 '20 at 11:28
  • I try to use virtualenv to create virutal env with python 3.6, if only altinstall, where to find the bin? – Lamp Dec 06 '22 at 02:05
  • found in /usr/local/bin – Lamp Dec 06 '22 at 02:07
12

Simply: The altinstall target will make sure the default Python on your machine is not touched, or to avoid overwriting the system Python.

S3DEV
  • 8,768
  • 3
  • 31
  • 42