OpenDevin Project Setup

A guide to set up your development environment for the OpenDevin project

Setting Up Your Development Environment

This guide will walk you through the steps to set up your development environment for the OpenDevin project. We’ll cover the installation of required tools, libraries, and dependencies, as well as the configuration of your project environment.

Prerequisites

Before you begin, ensure that you have the following prerequisites installed:

  • Ubuntu 22.04 LTS
  • Git

Step 1: Download Ubuntu 22.04

If you haven’t already, download the Ubuntu 22.04 LTS desktop version from the official Ubuntu website.

Step 2: Install Required Packages

Open the terminal and run the following commands to install the necessary packages:

1. NVIDIA Drivers

sudo ubuntu-drivers install

2. CUDA Toolkit

wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-ubuntu2204.pin
sudo mv cuda-ubuntu2204.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget https://developer.download.nvidia.com/compute/cuda/12.4.0/local_installers/cuda-repo-ubuntu2204-12-4-local_12.4.0-550.54.14-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu2204-12-4-local_12.4.0-550.54.14-1_amd64.deb
sudo cp /var/cuda-repo-ubuntu2204-12-4-local/cuda-*-keyring.gpg /usr/share/keyrings/
sudo apt-get update
sudo apt-get -y install cuda-toolkit-12-4
sudo apt-get install -y cuda-drivers

3. Docker Engine

sudo apt-get update
sudo apt-get install -y ca-certificates curl software-properties-common
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

After installing Docker, you need to be able to run Docker commands without sudo. To achieve this, follow these steps:

  1. Create a Unix group for Docker:
sudo groupadd docker
  1. Add your user to the Docker group:
sudo usermod -aG docker $USER
  1. Log out and log back in for the changes to take effect.

After logging back in, you should be able to run Docker commands without sudo. Verify this by running:

docker run hello-world

If the command runs without requiring sudo, you’ve successfully set up Docker to run without root privileges.

4. Anaconda

sudo apt-get install -y libgl1-mesa-glx libegl1-mesa libxrandr2 libxss1 libxcursor1 libxcomposite1 libasound2 libxi6 libxtst6
curl -o ~/Downloads/Anaconda3-2024.02-1-Linux-x86_64.sh https://repo.anaconda.com/archive/Anaconda3-2024.02-1-Linux-x86_64.sh
chmod +x ~/Downloads/Anaconda3-2024.02-1-Linux-x86_64.sh
bash ~/Downloads/Anaconda3-2024.02-1-Linux-x86_64.sh

After installing Anaconda, run the following commands to initialize and activate the base environment:

conda init
conda activate base

5. Ollama

curl -fsSL https://ollama.com/install.sh | sh

6. Node.js and npm

sudo apt update
sudo apt install -y nodejs npm

7. Pull Docker Image

docker pull ghcr.io/opendevin/sandbox:latest

Step 3: Set Up Your Project Environment

Now that you have all the required tools and libraries installed, it’s time to set up your project environment.

1. Create and Activate a Conda Environment

First, create a new Conda environment for your project:

conda create -n opendevin python=3.12 -y
conda activate opendevin

2. Install Pipenv

With your Conda environment activated, install Pipenv:

python -m pip install pipenv

3. Set Up Your Project with Pipenv

Navigate to your project directory and initialize your environment with Pipenv:

python -m pipenv install -v

4. Activate the Pipenv Shell

To work within your project’s virtual environment, activate the Pipenv shell:

python -m pipenv shell

5. Run Your Application

With the project’s virtual environment activated, you can start your application. For example, to run a FastAPI application using uvicorn:

uvicorn your_project.server:app --port 3000

Replace your_project.server:app with the appropriate Python module path for your application.

6. Set Up the Frontend (if applicable)

If your project includes a frontend that uses Node.js and npm, navigate to the frontend directory from a new terminal or tab (to keep the backend server running). Install the required npm packages:

cd frontend
npm install

Start the frontend development server:

npm start

Resuming Your Project Work

Whenever you start a new terminal session and want to work on your project, follow these steps:

  1. Activate your Conda environment:
conda activate opendevin
  1. Navigate to your project directory and activate the Pipenv environment:
cd /path/to/your/project
python -m pipenv shell
  1. Start your backend application (if applicable):
uvicorn your_project.server:app --port 3000
  1. If you have a separate frontend, open a new terminal or tab, activate your Conda environment (conda activate opendevin), navigate to the frontend directory, and start the development server:
cd /path/to/your/frontend
npm start

Resuming Your Project Work

  1. Activate Your Conda Environment: Whenever you start a new terminal session and want to work on your project, the first step is to activate the Conda environment you created for your project. Use the command below, replacing myenv with the name of your Conda environment:

    conda activate myenv
    

    This step ensures that any Python or command-line tools you use are limited to the dependencies and versions installed within this environment, maintaining project consistency and avoiding conflicts with other projects.

  2. Activate Your Pipenv Environment: Next, navigate to your project directory where your Pipfile exists and activate the Pipenv environment. This step is crucial if you’re working on Python projects managed by Pipenv, as it ensures you’re using the correct versions of Python packages specified for your project:

    cd /path/to/your/project
    python -m pipenv shell
    

    This command activates the virtual environment for your project, configured by Pipenv. You’ll need to do this every time you work on your project to ensure you’re using the right Python environment.

  3. Start Your Backend Application: If your project includes a backend component (like a FastAPI application), start it with the relevant command. For a FastAPI app using Uvicorn, for example:

    uvicorn your_project.server:app --port 3000
    

    Make sure to replace your_project.server:app with the path to your application’s main module. This command needs to be run from within the Pipenv shell activated in step 2.

  4. Start Your Frontend Development Server: If you have a frontend that runs separately (like a React or Vue application), you’ll need to open a new terminal or a new tab. If the frontend requires any environment configurations from the Conda environment, activate the Conda environment again with conda activate myenv. Then navigate to your frontend directory:

    cd /path/to/your/frontend
    npm start
    

    This step launches the development server for your frontend, often with live reloading enabled, so you can continue working on the frontend with immediate feedback on changes.

Code example

#!/bin/bash

# Set configuration variables
CUDA_VERSION="12.4.0"
ANACONDA_VERSION="2024.02-1"
UBUNTU_VERSION=$(lsb_release -rs)

# Define functions
install_nvidia_drivers() {
    echo "Installing NVIDIA drivers..."
    sudo ubuntu-drivers install
}

install_cuda() {
    echo "Installing CUDA Toolkit $CUDA_VERSION..."
    wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu${UBUNTU_VERSION/./}/x86_64/cuda-ubuntu${UBUNTU_VERSION//.}.pin
    sudo mv cuda-ubuntu${UBUNTU_VERSION//.}.pin /etc/apt/preferences.d/cuda-repository-pin-600
    wget https://developer.download.nvidia.com/compute/cuda/${CUDA_VERSION}/local_installers/cuda-repo-ubuntu${UBUNTU_VERSION/./}-${CUDA_VERSION/-/_}-local_${CUDA_VERSION/-/_}-550.54.14-1_amd64.deb
    sudo dpkg -i cuda-repo-ubuntu${UBUNTU_VERSION/./}-${CUDA_VERSION/-/_}-local_${CUDA_VERSION/-/_}-550.54.14-1_amd64.deb
    sudo cp /var/cuda-repo-ubuntu${UBUNTU_VERSION/./}-${CUDA_VERSION/-/_}-local/cuda-*-keyring.gpg /usr/share/keyrings/
    sudo apt-get update
    sudo apt-get -y install cuda-toolkit-${CUDA_VERSION/-/.}
    sudo apt-get install -y cuda-drivers
}

install_docker() {
    echo "Installing Docker..."
    sudo apt-get install -y ca-certificates curl software-properties-common
    sudo mkdir -p /etc/apt/keyrings
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
    echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
    sudo apt-get update
    sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

    echo "Setting up Docker to run without sudo..."
    sudo groupadd docker
    sudo usermod -aG docker $USER

    echo "Log out and log back in for the changes to take effect."
    echo "After logging back in, you can run 'docker run hello-world' to verify that Docker is running without sudo."
}

install_anaconda() {
    echo "Installing Anaconda $ANACONDA_VERSION..."
    sudo apt-get install -y libgl1-mesa-glx libegl1-mesa libxrandr2 libxss1 libxcursor1 libxcomposite1 libasound2 libxi6 libxtst6
    curl -o ~/Downloads/Anaconda3-${ANACONDA_VERSION}-Linux-x86_64.sh https://repo.anaconda.com/archive/Anaconda3-${ANACONDA_VERSION}-Linux-x86_64.sh
    chmod +x ~/Downloads/Anaconda3-${ANACONDA_VERSION}-Linux-x86_64.sh
    bash ~/Downloads/Anaconda3-${ANACONDA_VERSION}-Linux-x86_64.sh -b
}

install_ollama() {
    echo "Installing Ollama..."
    curl -fsSL https://ollama.com/install.sh | sh
}

install_nodejs() {
    echo "Installing Node.js and npm..."
    sudo apt update
    sudo apt install -y nodejs npm
}

pull_docker_image() {
    echo "Pulling Docker image..."
    docker pull ghcr.io/opendevin/sandbox:latest
}

# Check for prerequisites
check_prerequisites() {
    if [ ! -d /etc/apt/keyrings ]; then
        sudo mkdir -p /etc/apt/keyrings
    fi

    if ! command -v wget &> /dev/null; then
        sudo apt-get install -y wget
    fi

    if [ "$(uname -m)" != "x86_64" ]; then
        echo "This script is only supported on x86_64 architecture."
        exit 1
    fi

    if [ ! -d ~/Downloads ]; then
        mkdir ~/Downloads
    fi
}

# Uninstall function
uninstall() {
    echo "Uninstalling installed packages..."
    sudo apt-get remove -y --autoremove cuda-toolkit-${CUDA_VERSION/-/.} cuda-drivers docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin nodejs npm
    rm -rf ~/anaconda3
    sudo rm -rf /etc/apt/keyrings/docker.gpg /etc/apt/sources.list.d/docker.list /var/lib/docker /var/lib/containerd
}

# Main script
check_prerequisites

echo "This script will install the following packages:"
echo "- NVIDIA drivers"
echo "- CUDA Toolkit $CUDA_VERSION"
echo "- Docker Engine"
echo "- Anaconda $ANACONDA_VERSION"
echo "- Ollama"
echo "- Node.js and npm"
echo "- Docker image: ghcr.io/opendevin/sandbox:latest"

read -p "Do you want to continue? (y/n) " choice
case "$choice" in
    y|Y)
        install_nvidia_drivers
        install_cuda
        install_docker
        install_anaconda
        install_ollama
        install_nodejs
        pull_docker_image
        ;;
    n|N)
        echo "Installation canceled."
        exit 0
        ;;
    *)
        echo "Invalid choice."
        exit 1
        ;;
esac

echo "Anaconda is installed. Please manually run 'source ~/anaconda3/bin/activate' and then 'conda init' to finish setting it up."
echo "Remember to activate the Conda environment and follow the guide for any application-specific setup."
Last modified March 31, 2024: Update 001.md (6087387)