Setting Up Your ROS 2 Environment
You've learned why ROS 2 matters. Now it's time to get it running on your machine (or in the cloud).
This lesson offers two paths: Local Installation (if you have Ubuntu or WSL) or Cloud ROS 2 (if you prefer browser-based access). Both paths lead to the same destination—a working ROS 2 Humble environment where you can run commands and launch applications.
Duration: 60 minutes | Hardware Tier: Tier 1 (cloud OR local) | No coding yet—setup and verification only
Understanding Your Two Paths
Before you choose, understand what each path offers:
Path A: Cloud ROS 2 (Easiest, Recommended)
Best for: Students without Ubuntu, minimal installation hassle, guaranteed compatibility
What you get:
- Browser-based ROS 2 terminal (no installation)
- Pre-configured ROS 2 Humble environment
- VNC remote desktop for GUI applications
- No dependency conflicts
Time investment: 5 minutes (signup + launch)
Where: The Construct (TheConstruct.org) — free tier includes cloud ROS 2
Path B: Local Installation (Fastest Execution, More Setup)
Best for: Students with Ubuntu Linux or WSL, who want local execution speed
What you get:
- Native ROS 2 on your machine
- Faster command execution than cloud
- Full control over installation
- Works offline after setup
Time investment: 15-20 minutes (installation + verification)
Where: Your Ubuntu 22.04 machine (or WSL on Windows)
Choose Your Path
Decision Guide:
| Question | Path A (Cloud) | Path B (Local) |
|---|---|---|
| Do you have Ubuntu 22.04? | No problem! | Use this ✅ |
| Do you want fastest execution? | Skip this | Try this ✅ |
| Want to avoid installation? | Perfect ✅ | Skip this |
| Have limited disk space? | Yes ✅ | Requires ~5GB |
| Work offline often? | No | Yes ✅ |
Most students choose Path A first, then graduate to Path B for speed.
Path A: Cloud ROS 2 (TheConstruct)
Step 1: Create a Free Account
- Go to TheConstruct.org
- Click Sign Up
- Create account with email/password
- Verify email (check spam folder)
Estimated time: 3 minutes
Step 2: Launch a ROS 2 Environment
- Log in to your The Construct account
- Click MY COURSES → Create New Rosject
- Configure:
- Name: "ROS 2 Learning" (or your choice)
- ROS Distribution: Select ROS 2 Humble
- Type: Select ROS Desktop (includes visualization tools)
- Click Create Rosject
Wait: The system launches your environment (~30 seconds)
Step 3: Access Your Terminal
Once launched, you'll see a web interface with:
- Left sidebar: File browser
- Center: Text editor (not needed yet)
- Right panel: Open Shell button
Click Open Shell to open a terminal.
You now have a working ROS 2 Humble environment in your browser.
Verify it works:
echo $ROS_DISTRO
Expected output:
humble
If you see humble, you're done with setup! Skip to "Environment Verification" below.
Path B: Local Installation (Ubuntu/WSL)
Prerequisites
- Ubuntu 22.04 LTS (native or WSL on Windows)
- Sudo access (ability to run
sudocommands) - ~5GB disk space for ROS 2 + dependencies
- 15-20 minutes of patience
Step 1: Add ROS 2 Repository
Open a terminal and run:
sudo apt update
sudo apt install curl gnupg lsb-release
sudo curl -sSL https://repo.ros2.org/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros2.org/ubuntu $(source /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
This adds the official ROS 2 repository to your package manager.
If errors occur: Run sudo apt update and retry the commands above.
Step 2: Install ROS 2 Humble
sudo apt update
sudo apt upgrade
sudo apt install ros-humble-desktop
What happens:
- Terminal shows progress (may take 5-10 minutes)
- Asks for your password (enter it)
- Installs ROS 2, Python libraries, build tools
When complete: You see a fresh prompt with no errors.
Step 3: Source the Setup Script
Add ROS 2 to your shell environment:
source /opt/ros/humble/setup.bash
What this does:
- Adds ROS 2 executables to your PATH
- Sets
ROS_DISTROenvironment variable - Configures Python paths for ROS 2 packages
Make it automatic (recommended):
Add the source command to your shell startup file so it runs every time you open a terminal:
echo "source /opt/ros/humble/setup.bash" >> ~/.bashrc
source ~/.bashrc
Now every new terminal automatically loads ROS 2.
Environment Verification (Both Paths)
Regardless of which path you chose, verify your installation works:
Check 1: ROS Distro
echo $ROS_DISTRO
Expected output: humble
If blank or error: You skipped the sourcing step. Run:
source /opt/ros/humble/setup.bash # Cloud: skip this, already sourced
source ~/.bashrc # Local: verify setup
Check 2: ROS 2 Commands Available
ros2 --version
Expected output:
ROS 2 humble (release date: 2023-05-23)
Check 3: Find ROS Packages
ros2 pkg list | head -10
This shows the first 10 installed ROS 2 packages. You should see output like:
ament_cmake
ament_cmake_auto
ament_cmake_gmock
ament_cmake_google_benchmark
...
If no output: Sourcing didn't work. Restart your terminal and retry Check 1.
Check 4: Python Path for ROS 2
python3 -c "import rclpy; print('✓ rclpy installed')"
Expected output: ✓ rclpy installed
If ModuleNotFoundError: ROS 2 isn't sourced. Retry sourcing and restart terminal.
Troubleshooting
"Command ros2 not found"
Cause: ROS 2 not sourced or installation incomplete
Fix:
- Run
source /opt/ros/humble/setup.bash - Restart terminal
- Try again
For permanent fix: Add to ~/.bashrc (already done if you followed Step B3)
"ROS_DISTRO is empty"
Cause: Sourcing failed
Fix:
- Verify file exists:
ls /opt/ros/humble/setup.bash(local) or check The Construct terminal - Run source command:
source /opt/ros/humble/setup.bash - Verify:
echo $ROS_DISTRO
Installation Failed (Local Path)
If apt install gave errors:
- Check Ubuntu version:
lsb_release -cs(should bejammyfor 22.04) - Re-add repository (might have typo)
- Try again:
sudo apt install ros-humble-desktop
If still failing: Use Cloud Path instead (no installation needed)
"Permission denied" errors
Cause: Missing sudo
Fix: Prefix commands with sudo:
sudo apt update
sudo apt install ...
Understanding Your Environment
Now that ROS 2 is running, understand what you just set up:
Workspace Structure (Local Installation)
When you install ROS 2 locally, it creates:
/opt/ros/humble/ # ROS 2 installation directory
├── bin/ # Executables (ros2 command, etc.)
├── lib/ # Libraries
├── share/ # Packages and data files
└── setup.bash # Script that sets up environment
When you run source setup.bash, the script:
- Adds
/opt/ros/humble/bin/to PATH (soros2command is found) - Sets
ROS_DISTRO=humble(tells ROS 2 which version to use) - Configures
PYTHONPATH(so Python findsrclpylibrary)
Package Discovery (Cloud and Local)
When you run ros2 pkg list, ROS 2 searches for packages in directories specified by ROS_PACKAGE_PATH.
For a clean installation, these are all in /opt/ros/humble/share/.
Later (Chapters 4-7), you'll create your own packages in a workspace (~/ros2_ws/), and they'll automatically be discoverable once sourced.
Next Steps
You now have a working ROS 2 Humble environment. In the next lesson, you'll:
- Launch turtlesim—a simple 2D robot simulator
- Control it with keyboard input
- See ROS 2's publish/subscribe system in action
But before that, let's lock in your understanding with a brief checkpoint.
Try With AI
Setup: Open your favorite AI tool (ChatGPT, Claude, or similar) and your ROS 2 terminal side by side.
Prompt 1 (Understanding PATH):
Ask your AI:
I just ran 'source /opt/ros/humble/setup.bash'.
What does this command actually do to my shell?
Explain what PATH environment variable is and why ROS 2 needs to modify it.
Expected insight: PATH tells your shell where to find executables. Understanding this helps you troubleshoot "command not found" errors later.
Prompt 2 (Verification Check):
Ask your AI:
I'm verifying my ROS 2 installation. I ran these checks:
- echo $ROS_DISTRO → outputs "humble" ✓
- ros2 --version → outputs "ROS 2 humble (release date: 2023-05-23)" ✓
- ros2 pkg list | head → shows packages ✓
- python3 -c "import rclpy" → outputs nothing (success) ✓
Is my installation complete and correct? What might still be missing?
Expected insight: AI may suggest verifying ROS_DOMAIN_ID or RMW_IMPLEMENTATION (advanced settings you don't need yet). Installation can have depth beyond the basics.
Prompt 3 (Failure Recovery):
Ask your AI this scenario:
I get the error: "ros2: command not found" even after running "source /opt/ros/humble/setup.bash".
What are 3 things I should check, and how would I diagnose each one?
What you learn: Systematic troubleshooting. The AI teaches you that errors have multiple possible causes (wrong path, sourcing in wrong shell, incomplete installation), and you can rule them out one by one.
Optional Extension:
If you're curious about your specific installation, ask:
Show me what happens when I run 'source /opt/ros/humble/setup.bash' step-by-step.
What environment variables change? Which files get added to PATH?
This deepens your mental model of how ROS 2 installation works.
Checkpoint
Before moving to Lesson 3.2, verify you can:
- Run
echo $ROS_DISTROand seehumble - Run
ros2 --versionand see version output - Run
ros2 pkg list | head -5and see packages - (If local path) Understand where ROS 2 is installed (
/opt/ros/humble/) - (If cloud path) Know how to access your The Construct terminal
If all boxes are checked, you're ready to launch turtlesim in Lesson 3.2.
If any failed, re-read the troubleshooting section or ask your AI tool for help.
Next lesson: → Lesson 3.2: Turtlesim in Action