How To Install Anaconda On Linux, Windows, MacOS Correctly

Anaconda is a scientific Python distribution that contains a lot of not often used scientific python libraries. If you want to do data analysis, scientific computing, you can install the anaconda and use it to implement what you want.

But after I install anaconda on Linux, I found that I can not use it correctly. When I input command such as jupyter notebook, it shows error message like Error executing Jupyter command ‘notebook’: [Errno 2] No such file or directory. But you can follow this article to fix the errors.

1. Install Anaconda On Linux, Windows, MacOS.

  1. The anaconda installation is very simple and straightforward. The installation process on all three platforms ( Linux, Windows, macOS ) is very similar.
  2. But before that, you should download anaconda for your OS platform first. After that follow the below steps to install it on the different OS platforms.

1.1 Linux.

  1. Anaconda Linux install file is just a .sh file, it is executable.
  2. First, open a terminal to run the command chmod +x to add executable permission.
  3. Then run the file to install anaconda.
  4. The installation process is very straightforward. It will download and install a lot of dependency libraries.
  5. Remember the anaconda3 installed directory that is printed on the screen during the installation process like below.
    Anaconda3 will now be installed into this location:
      - Press ENTER to confirm the location
      - Press CTRL-C to abort the installation
      - Or specify a different location below
    [/home/jerry/anaconda3] >>> 
  6. When the installation comes to the text Do you wish the installer to initialize Anaconda3, type yes to initialize it.
    installation finished.
    Do you wish the installer to initialize Anaconda3
    by running conda init? [yes|no]
    [no] >>> 
  7. After installation, you need to close the current terminal and open a new terminal to make the changes take effect.
    ./ 489: [[: not found
    no change     /home/jerry/anaconda3/condabin/conda
    no change     /home/jerry/anaconda3/bin/conda
    no change     /home/jerry/anaconda3/bin/conda-env
    no change     /home/jerry/anaconda3/bin/activate
    no change     /home/jerry/anaconda3/bin/deactivate
    no change     /home/jerry/anaconda3/etc/profile.d/
    no change     /home/jerry/anaconda3/etc/fish/conf.d/
    no change     /home/jerry/anaconda3/shell/condabin/Conda.psm1
    no change     /home/jerry/anaconda3/shell/condabin/conda-hook.ps1
    no change     /home/jerry/anaconda3/lib/python3.9/site-packages/xontrib/conda.xsh
    no change     /home/jerry/anaconda3/etc/profile.d/conda.csh
    modified      /home/jerry/.bashrc
    ==> For changes to take effect, close and re-open your current shell. <==
  8. After installation, the anaconda bin directory path is also added in the system PATH env variable by changing your .bashrc ( /home/zhaosong/.bashrc ) file automatically as below.
    # added by Anaconda3 2018.12 installer
    # >>> conda init >>>
    # !! Contents within this block are managed by 'conda init' !!
    __conda_setup="$(CONDA_REPORT_ERRORS=false '/home/zhaosong/anaconda3/bin/conda' shell.bash hook 2> /dev/null)"
    if [ $? -eq 0 ]; then
        \eval "$__conda_setup"
        if [ -f "/home/zhaosong/anaconda3/etc/profile.d/" ]; then
            . "/home/zhaosong/anaconda3/etc/profile.d/"
            CONDA_CHANGEPS1=false conda activate base
            \export PATH="/home/zhaosong/anaconda3/bin:$PATH"
    unset __conda_setup
    # <<< conda init <<<
  9. Do not forget to run $ source .bashrc to make the changes take effect. Otherwise, you may encounter errors when you run ipython or jupyter.
  10. If you meet the above error, you also first need to check the PATH environment variable’s value, you should make sure the anaconda bin directory path locate at beginning of the PATH value.
    ~$ echo $PATH
  11. If everything is correct, run python in a terminal, you can see Anaconda in the output text.
    ~$ python
    Python 3.7.1 (default, Dec 14 2018, 19:28:38) 
    [GCC 7.3.0] :: Anaconda, Inc. on linux
    Type "help", "copyright", "credits" or "license" for more information.
  12. Now run jupyter notebookcommand in a terminal, it will start up a web server and you can access it with URL http://localhost:8888/tree.
    $ jupyter notebook
    [I 22:21:57.057 NotebookApp] Writing notebook server cookie secret to /run/user/1000/jupyter/notebook_cookie_secret
    [I 22:21:57.234 NotebookApp] JupyterLab extension loaded from /home/zhaosong/anaconda3/lib/python3.7/site-packages/jupyterlab
    [I 22:21:57.234 NotebookApp] JupyterLab application directory is /home/zhaosong/anaconda3/share/jupyter/lab
    [I 22:21:57.235 NotebookApp] Serving notebooks from local directory: /home/zhaosong
    [I 22:21:57.235 NotebookApp] The Jupyter Notebook is running at:
    [I 22:21:57.236 NotebookApp] http://localhost:8888/?token=a1ccb7865e275163dbd751856698a601f6f69feb2627b266
    [I 22:21:57.236 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
    [C 22:21:57.254 NotebookApp] 
        To access the notebook, open this file in a browser:
        Or copy and paste one of these URLs:
  13. To open the Anaconda navigator, you can run the command anaconda-navigator in the terminal, after a while you can see the Anaconda Navigator window.

1.2 Windows.

  1. Double click the installation file and follow the wizard steps to install.
  2. You should pay attention to the Select Installation Type wizard, there are 2 radio buttons behind the Install for, one is Just Me (recommended), the other is All Users(requires admin privileges).
  3. When you select the Just Me radio button, it will install anaconda under the user directory and it will not add the anaconda install path to the System Path environment variable, you should add it to the User variables Path environment variable, you can read the article How To Fix Python Can Not Be Recognized In Windows Command After Adding It To System Path Variable to learn more.
  4. When you select the All Users radio button and when the installation is complete, the installer will add the anaconda bin directory in the PATH system environment variable.
  5. Open a dos window and run the python command, if you see something like below, it means anaconda has been installed successfully in your Windows.
    C:> python
    Python 3.7.1 (default, Dec 14 2018, 19:28:38) 
    [GCC 7.3.0] :: Anaconda, Inc. on windows
    Type "help", "copyright", "credits" or "license" for more information.
  6. If you have installed another python version before, and the output does not contain Anaconda, you need to check the PATH system environment variable, to check whether the anaconda installation path is included at the beginning of the PATH variable value or not.
  7. If you do not know where the anaconda is installed on Windows, you can read the article How To Find Where Anaconda Python Is Installed.

1.3 macOS.

  1. Install anaconda on macOS is very similar to Windows.
  2. The difference is that the downloaded file is a .pkg file.
  3. Double click the .pkg file to install it.
  4. After installation, the bin folder ( anaconda executable file saved folder  ) in the anaconda installation directory will be added to /Users/$USER/.bash_profile automatically.
  5. To make sure the PATH value change take effect, run source .bash_profile command in a terminal.
  6. To verify the anaconda installation is successful, open a terminal and run python or ipython command, then you should see anaconda in the output text.
  7. If it shows an error message, you should run env command in terminal to check the PATH environment variable value, to see whether it’s value contains the anaconda bin folder or not.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.