DEV Community

Monika Prajapati
Monika Prajapati

Posted on • Originally published at blog.monikaprajapati.com.np

Quick Guide: Installing Conda on EC2 (The Right Way)

Look, installing Conda on EC2 doesn't need to be complicated. After setting this up across hundreds of instances, here's my approach that just works.

The Fast Track

Skip the fluff. Here's what actually works:

wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh
bash ~/miniconda.sh -b -p $HOME/miniconda
~/miniconda/bin/conda init bash
source ~/.bashrc
Enter fullscreen mode Exit fullscreen mode

Done. That's it. If you're in a hurry, you can stop reading here.

When Things Break

The Command Not Found Thing

Got the "conda: command not found" error? Yeah, we've all been there. The -b flag skips initialization. Just run:

~/miniconda/bin/conda init bash
source ~/.bashrc
Enter fullscreen mode Exit fullscreen mode

Fixed. Moving on.

Existing Installation

ERROR: File or directory already exists: '/home/ec2-user/miniconda'
Enter fullscreen mode Exit fullscreen mode

Two options:

# Quick update
bash ~/miniconda.sh -u -b -p $HOME/miniconda

# Or nuke it and start fresh
rm -rf $HOME/miniconda && bash ~/miniconda.sh -b -p $HOME/miniconda
Enter fullscreen mode Exit fullscreen mode

Production Setup

Here's my actual production setup script. Copy-paste and thank me later:

#!/bin/bash
sudo yum update -y

# Skip if you've handled these in your AMI
sudo yum install -y bzip2 wget git

# Base install
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh
bash ~/miniconda.sh -b -p $HOME/miniconda
~/miniconda/bin/conda init bash
source ~/.bashrc

# The stuff you actually need
conda config --add channels conda-forge
conda config --set channel_priority strict
conda clean -a -y  # Trust me on this one

# Create your env
conda create -n prod python=3.11 -y
conda activate prod
conda install numpy pandas scikit-learn -y  # Add your packages
Enter fullscreen mode Exit fullscreen mode

For the DevOps Folks

Throw this in your user data and forget about it:

#!/bin/bash
cat <<'EOF' > /home/ec2-user/setup_conda.sh
#!/bin/bash
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh
bash ~/miniconda.sh -b -p $HOME/miniconda
~/miniconda/bin/conda init bash
EOF

chmod +x /home/ec2-user/setup_conda.sh
sudo -u ec2-user /home/ec2-user/setup_conda.sh
Enter fullscreen mode Exit fullscreen mode

The "Why" Behind the Choices

  • Miniconda over Anaconda: Smaller footprint, faster installs. You don't need the bloat.
  • conda-forge first: Better packages, fewer headaches.
  • Always clean after big installs: Saves space, prevents weird caching issues.
  • Separate envs: Just do it. Future you will be grateful.

Storage Notes

Quick reality check before you start:

df -h
Enter fullscreen mode Exit fullscreen mode

Miniconda needs about 400MB. Your envs will grow. Plan accordingly or attach an EBS volume.

Container World

If you're using containers (and you probably should be), here's your Dockerfile snippet:

FROM amazonlinux:2

RUN yum update -y && \
    yum install -y bzip2 wget && \
    wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O /miniconda.sh && \
    bash /miniconda.sh -b -p /opt/conda && \
    rm /miniconda.sh

ENV PATH="/opt/conda/bin:${PATH}"

RUN conda install -y python=3.11 && \
    conda clean -a -y

WORKDIR /app
Enter fullscreen mode Exit fullscreen mode

One Last Thing

Always export your environment:

conda env export > environment.yml
Enter fullscreen mode Exit fullscreen mode

Don't be that person who can't reproduce their env six months later.

That's it. No fluff, just what works. If you've got questions, you know where to find me.

Image of AssemblyAI tool

Challenge Submission: SpeechCraft - AI-Powered Speech Analysis for Better Communication

SpeechCraft is an advanced real-time speech analytics platform that transforms spoken words into actionable insights. Using cutting-edge AI technology from AssemblyAI, it provides instant transcription while analyzing multiple dimensions of speech performance.

Read full post

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay