116

How to install Anaconda for Python on Ubuntu?

Is there a way to use apt-get install?

I only have command line access to my server. How do I install Anaconda on Ubuntu 14.04 from the command line?

muru
  • 207,228
alvas
  • 3,027

11 Answers11

93

You can use wget to download from commandline:

For Python3, 64 bits version (most Ubuntu distros)

    wget https://repo.anaconda.com/archive/Anaconda3-2022.05-Linux-x86_64.sh

And after download is finished do:

    bash Anaconda3-2022.05-Linux-x86_64.sh

For users using Python2, the "3" directly after Anaconda should be changed to a 2.

Source: https://docs.conda.io/projects/conda/en/stable/user-guide/install/linux.html

Vivek
  • 1,440
65

See Anaconda Hompepage for more detail!

Installation Instructions [Linux Install]

These instructions explain how to install Anaconda on a Linux system.

After downloading the Anaconda installer, run the following command from a terminal:

$ bash Anaconda-2.x.x-Linux-x86[_64].sh

After accepting the license terms, you will be asked to specify the install location (which defaults to ~/anaconda).

Note: You do NOT need root privileges to install Anaconda, if you select a user writable install location, such as ~/anaconda.* After the self extraction is finished, you should add the anaconda binary directory to your PATH environment variable.

As all of Anaconda is contained in a single directory, uninstalling Anaconda is easy (you simply remove the entire install location directory).


If you encounter any issues, please try disabling your antivirus software. Linux/OS X Uninstall

As all of Anaconda is contained in a single directory, uninstalling Anaconda is simple (you simply remove the entire install location directory):

$ rm -rf ~/anaconda
v2r
  • 9,707
64

Nobody has explained here why apt-get and other package managers don't have packages for anaconda.

An important reason for this is that anaconda is meant to be usable by a user who, for whatever reason, doesn't have root privileges. In that case the user just installs into ~/anaconda, changes her own PATH and PYTHONHOME variables so as to run ~/anaconda/python, and is capable of controlling her personal python distribution, while modifying the "system" python might require an administrator's help.

Package managers always require sysadmin privileges.

Zanna
  • 72,312
24

If you are trying to it entirely in command line you use a bash script python 2 anaconda install bash script:

# Go to home directory
cd ~

# You can change what anaconda version you want at 
# https://repo.continuum.io/archive/
wget https://repo.continuum.io/archive/Anaconda2-4.2.0-Linux-x86_64.sh
bash Anaconda2-4.2.0-Linux-x86_64.sh -b -p ~/anaconda
rm Anaconda2-4.2.0-Linux-x86_64.sh
echo 'export PATH="~/anaconda/bin:$PATH"' >> ~/.bashrc 

# Reload default profile
source ~/.bashrc

conda update conda

python 3 anaconda install bash script

# Go to home directory
cd ~

# You can change what anaconda version you want at 
# https://repo.continuum.io/archive/
wget https://repo.continuum.io/archive/Anaconda3-4.2.0-Linux-x86_64.sh
bash Anaconda3-4.2.0-Linux-x86_64.sh -b -p ~/anaconda
rm Anaconda3-4.2.0-Linux-x86_64.sh
echo 'export PATH="~/anaconda/bin:$PATH"' >> ~/.bashrc 

# Reload default profile
source ~/.bashrc

conda update conda

Source: https://medium.com/@GalarnykMichael/install-python-on-ubuntu-anaconda-65623042cb5a

13

In addition to @Vivek's answer, to get the latest python3 64-bit Linux version:

CONTREPO=https://repo.continuum.io/archive/
# Stepwise filtering of the html at $CONTREPO
# Get the topmost line that matches our requirements, extract the file name.
ANACONDAURL=$(wget -q -O - $CONTREPO index.html | grep "Anaconda3-" | grep "Linux" | grep "86_64" | head -n 1 | cut -d \" -f 2)
wget -O ~/Downloads/anaconda.sh $CONTREPO$ANACONDAURL
bash ~/Downloads/anaconda.sh -b -p $HOME/anaconda3

The grep filters in line 3 can be altered to match your requirements, of course.

Q: What is going on here?

  • wget -q -O - URL quietly (-q) gets the html at URL (in this case https://repo.continuum.io/archive/, which is accessed as $CONTREPO) and sends it to standard out (-O -).
  • | is called "pipe", and sends the output of the preceding command to the next command.
  • grep "text" returns the lines from its input that contain text. So first, we select all lines that contain "Anaconda3", then of those, we select all lines containing "Linux", and then all lines containing "86_64" (for the 64-bit version).
  • head -n 1 returns the first line of the input. I rely on the website maintaining order so that the most recent version is on top.
  • cut -d \" -f 2 splits the input on the double quote characters (-d \"), which surround the filename in the HTML's href, and returns the second field (-f 2), being the target of the href.
  • -b -p path options make the installation non-interactive "silent-mode", where you silently accept the license and are not asked for confirmation for the installation path.
6

Watch this video for complete installation

Download Anaconda from continuum here

To install Python 3.6 version

sudo bash Anaconda3-4.3.0-Linux-x86_64.sh 

For Python 2.7 version

 sudo bash Anaconda2-4.3.0-Linux-x86_64.sh

Run Navigator

anaconda-navigator

Run Spyder IDE

spyder

Run Jupyter Notebook

jupyter-notebook
Zanna
  • 72,312
4

Follow these steps:

  1. export PATH="~/anaconda/bin:$PATH"
  2. Then you can update them with:

    conda update conda
    conda update anaconda
    
2

You can use Pyenv to install Anaconda, and then easily switch back and forth between your system Python and your Anaconda Python:

  1. Install Pyenv
  2. pyenv install anaconda3-5.3.0 (pynev install -l to see what versions of anaconda are available)
yndolok
  • 121
2

Take a look at the Anaconda repo archive page and select an appropriate version that you'd like to install.

After that, just do:

 # replace this `Anaconda3-version.num-Linux-x86_64.sh` with your choice
~$ wget -c https://repo.continuum.io/archive/Anaconda3-vers.num-Linux-x86_64.sh
~$ bash Anaconda3-version.num-Linux-x86_64.sh

Concrete Example:

As of this writing, Anaconda3-2019.03 is the latest version. So,

$ wget -c https://repo.continuum.io/archive/Anaconda3-5.0.1-Linux-x86_64.sh
$ bash Anaconda3-5.0.1-Linux-x86_64.sh

After installation is completed, you can also optionally delete the installation script by:

$ rm -rf Anaconda3-5.0.1-Linux-x86_64.sh
kmario23
  • 1,039
2

It sounds like you might want a apt-based way of installing things. Anaconda maintains an apt repo for conda which allows for installation of one version of conda for all the users on a system.

as of 2023, anaconda has instructions on how to to this

The short version: (note, requires root access)

Install our public gpg key to trusted store

curl https://repo.anaconda.com/pkgs/misc/gpgkeys/anaconda.asc | gpg --dearmor > conda.gpg
install -o root -g root -m 644 conda.gpg /usr/share/keyrings/conda-archive-keyring.gpg

Check whether fingerprint is correct (will output an error message otherwise)

gpg --keyring /usr/share/keyrings/conda-archive-keyring.gpg --no-default-keyring --fingerprint 34161F5BF5EB1D4BFBBB8F0A8AEB4F8B29D82806

Add our Debian repo

As root do: # echo "deb [arch=amd64 signed-by=/usr/share/keyrings/conda-archive-keyring.gpg] https://repo.anaconda.com/pkgs/misc/debrepo/conda stable main" > /etc/apt/sources.list.d/conda.list

NB: If you receive a Permission denied error when trying to run the above command (because /etc/apt/sources.list.d/conda.list is write protected), try using the following command instead:

# echo "deb [arch=amd64 signed-by=/usr/share/keyrings/conda-archive-keyring.gpg] https://repo.anaconda.com/pkgs/misc/debrepo/conda stable main" | sudo tee -a /etc/apt/sources.list.d/conda.list

Then do the usual

$ sudo apt-get update

$ sudo apt-get install conda

For each user, they will need to add /opt/conda/bin:/opt/conda/condabin to their $PATH and do something like "conda init bash" to start using the system conda.

Alternatively, you can, as root,

# ln -s /opt/conda/etc/profile.d/conda.sh /etc/profile.d

So that it is installed system wide.

There are additional instructions on setting up a system-wide /opt/conda/.condarc file at the anaconda site.

[2] https://www.anaconda.com/blog/rpm-and-debian-repositories-for-miniconda

1

I think this is cleaner:

# install python
sudo apt-get update
sudo apt-get install wget

wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh bash ~/miniconda.sh -b -p $HOME/miniconda

source /Users/my_username/opt/anaconda3/bin/activate

source ~/miniconda/bin/activate

conda init zsh

conda init conda update -n base -c defaults conda conda install conda-build

conda create -n iit_synthesis python=3.9 conda activate iit_synthesis #conda remove --name metalearning2 --all

inspired from: