How To Install Anaconda On Linux

How To Install Anaconda On Linux

Reading time1 min
#DataScience#Python#Linux#Anaconda#Conda#MachineLearning

Mastering Anaconda Installation on Linux: Reliable Workflows Without Surprises

Anaconda underpins countless data science and ML pipelines. On Linux, its isolation, reproducibility, and package management save hours of debugging—assuming installation is correct. Here’s a concise, engineer-tested path to an operational stack.


Scenario:
"Conda command not found."
"Environment packages clashing with system Python."
If either of these look familiar, improper install location or missing shell integration is likely at fault. Let's establish a repeatable, stable base.

Why Deploy Anaconda on Linux?

  • Predictable Dependency Isolation: Avoids pervasive pip/apt mismatches common in multi-user or research systems.
  • Proven Data Stack: Jupyter, numpy, pandas, scikit-learn—all in tested combinations.
  • Simplified Upgrades: Update environments with explicit version pins; rollback if (when) something breaks.

1. Download the Current Linux Installer

Never assume URLs persist. Always cross-reference the official Anaconda archive for SHA256 and latest version.

Example for 2023.07-1, x86_64:

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

Not all clusters provide wget; curl -O ... is an alternative.


2. (Recommended) Validate the Installer’s Integrity

On a shared system or for regulated projects, verifying the installer prevents supply chain attacks.

sha256sum Anaconda3-2023.07-1-Linux-x86_64.sh
# Expected: 9a61bdfe3b8af0fe8d4107302a760eabd0cd881fa312c09721d57cce5b6fbb4a

Mismatch? Don’t proceed. Redownload or double-check the hash source.


3. Install in User Space—Avoid /usr/local

Default install path (~/anaconda3) is generally sufficient and avoids permission issues.

bash Anaconda3-2023.07-1-Linux-x86_64.sh

Proceed through EULA. When prompted for install location, press Enter unless you have quotas or disk layout constraints.

Note: On shared HPC clusters, $HOME sometimes has storage limits—prefer a path on local scratch if possible.


4. Initialize Conda for Shell Usage

A commonly missed step: If conda init isn’t completed, Conda won’t appear in $PATH.

Either allow the installer to run conda init, or manually execute:

~/anaconda3/bin/conda init bash
source ~/.bashrc

For Zsh, use conda init zsh; adjust accordingly for other shells.

Gotcha: Not initializing for the correct shell leads to misleading "command not found" errors—even after installation.


5. Verify and Inspect Installation

Check for a successful install:

conda --version
# Should output: conda 23.7.4 (or whichever version matches installer)

List environments—expect only base initially:

conda env list
# /home/youruser/anaconda3 (base)

Confirm executable paths:

which python
# /home/youruser/anaconda3/bin/python
which conda
# /home/youruser/anaconda3/bin/conda

If these point to /usr/bin or somewhere else, .bashrc likely wasn’t updated.


6. Update Conda (Highly Advised)

Initial installations are rarely up-to-date; resolve this before creating environments.

conda update -n base -c defaults conda
# When prompted, answer: y

Updating frequently pulls minor bugfixes critical for dependency solving.


7. Create Isolated Project Environments (Practical Example)

Best practice: Never install directly into base for real projects.

conda create --name experiment1 python=3.10
conda activate experiment1

Now, install typical data science packages—version-pin if strict reproducibility required:

conda install numpy=1.24 pandas=2.0 scikit-learn jupyter

Trade-off: Pinning older versions delays access to new features, but avoids breakage from upstream changes.


8. Side Note—Batch Install via environment.yml

For collaborating or CI, replace “install by hand” with:

# environment.yml
name: analysis-env
channels:
  - defaults
dependencies:
  - python=3.10
  - numpy
  - pandas
  - scikit-learn
  - jupyter

Deploy with:

conda env create -f environment.yml

Common Issues—and Checks

  • Permission Denied: Never sudo an Anaconda install; user locations avoid destructive collisions.
  • Hijacked $PATH: Double-check with echo $PATH—system Python before Anaconda usually signals shell init failure.
  • Leftover System Packages: Avoid pip install in base or system-site; Conda handles most mainstream data science libraries.

Non-obvious tip:
When using both Conda and system tools, always check which python or which pip before installing anything new. Misalignment causes cryptic import errors.


Wrapping Up

A clean Anaconda installation on Linux provides stable, isolated environments critical for dependable research and production workflows. Avoiding system-level installs minimizes accidental breakage—especially when multiple projects or users share hardware.

Anaconda is not perfect; for minimal use cases (or containers), consider Miniconda instead. For heavy custom C/C++ workloads, custom builds may still be needed.

As always, test your environments regularly and keep backups of any custom environment.yml files. That alone saves hours of recovery when a dependency tree mutates.


Known issue: Some desktop environments require terminal restart or full logout for $PATH changes to take effect. If in doubt, log out and back in after install.