Are you a developer working on a Debian-based Linux system (like Ubuntu or Kali Linux) and looking for a streamlined way to set up your development environment with Rust, essential build tools, and Docker? Look no further!
This article walks you through a powerful Bash script that automates the installation of these crucial tools, getting you up and running quickly.
Why Automate Your Dev Environment Setup?
Setting up a new machine or ensuring consistency across multiple development environments can be tedious and error-prone. Automation with a script like this ensures:
Consistency: Every setup is identical, reducing "it works on my machine" issues.
Speed: Install everything in minutes, not hours.
Reliability: Reduces human error during complex installations.
Reproducibility: Easily recreate your environment whenever needed.
The Automation Script Explained
Let's dive into the script and understand what each section does.
!/bin/bash
This script automates the setup of a comprehensive development environment
on Debian-based Linux systems (like Ubuntu or Kali Linux).
It includes Rust, essential build tools, and Docker with Docker Compose.
Exit immediately if a command exits with a non-zero status.
set -e
echo "Starting development environment setup..."
!/bin/bash: The shebang line, indicating that the script should be executed with Bash.
set -e: A critical command that ensures the script will exit immediately if any command fails. This prevents partial or broken installations.
echo: Used throughout the script to provide clear feedback on the installation progress.
- Install Rust Programming Language Rust is a modern systems programming language known for its performance, memory safety, and concurrency. rustup is its official installer and toolchain manager. # --- 1. Install Rust Programming Language --- echo "--- Installing Rust Programming Language ---" # Install rustup and the Rust toolchain curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Update your shell environment for the current session
This ensures cargo and rustc commands are immediately available
source "$HOME/.cargo/env"
echo "Rust installation complete. PATH updated for current session."
This section downloads and runs the rustup script, which installs the Rust compiler (rustc) and its package manager (cargo). The source "$HOME/.cargo/env" command updates your shell's PATH for the current session, making Rust commands immediately available.
- Install Essential Build Tools Many software projects, including some Rust crates, rely on underlying C/C++ libraries. build-essential provides the core compilers and utilities needed for this. # --- 2. Install Essential Build Tools --- echo "--- Installing Essential Build Tools ---" # Update package lists sudo apt update
Install build-essential (includes gcc, g++, make)
sudo apt install -y build-essential
echo "Build essential tools installed."
``sudo apt update
refreshes your package lists, and sudo apt install -y build-essential
installs gcc
, g++
, make
, and other crucial tools required for compiling C/C++ code. The -y
flag automatically confirms prompts.
3. Install Additional Development Dependencies
This section includes specific libraries and tools that are often required for various development tasks, especially those involving Perl or secure communication.
bash
# --- 3. Install Additional Development Dependencies (Perl, OpenSSL dev, pkg-config) ---
sudo apt-get install -y \
perl \
perl-base \
perl-modules \
libssl-dev \
pkg-config
echo "Additional development dependencies installed."
Here, perl and its base modules are installed. libssl-dev provides development headers for OpenSSL, essential for projects dealing with SSL/TLS encryption. pkg-config helps manage compilation flags for libraries.
4. Install libudev-dev
libudev-dev is a development library for udev, which handles device events in Linux. It's often a dependency for Rust crates that need to interact with hardware, such as USB devices.
# --- 4. Install libudev-dev ---
echo "--- Installing libudev-dev ---"
sudo apt-get install -y libudev-dev
echo "libudev-dev installed."
5. Install Docker
Docker is a game-changer for containerizing applications, ensuring consistent environments from development to production.
# --- 5. Install Docker ---
echo "--- Installing Docker ---"
# Install necessary packages for Docker's repository
sudo apt-get install -y \
ca-certificates \
curl \
gnupg \
lsb-release
# Add Docker's official GPG key
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 "Docker GPG key added."
# Set up the stable Docker repository
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
echo "Docker repository added."
# Update apt package index again after adding the new repository
sudo apt-get update
# Install Docker Engine
sudo apt-get install -y docker-ce docker-ce-cli containerd.io
echo "Docker Engine installed."
# Add user to docker group
sudo usermod -aG docker "$USER"
echo "User '$USER' added to the 'docker' group. IMPORTANT: You must log out and log back in (or reboot) for this change to take effect."
This section adds Docker's official repository and GPG key, then installs the Docker Engine, CLI, and containerd.io. Crucially, it adds your current user to the docker group, allowing you to run Docker commands without sudo (after a re-login).
6. Install Docker Compose
Docker Compose simplifies the management of multi-container Docker applications, allowing you to define your services in a single docker-compose.yml file.
# --- 6. Install Docker Compose ---
echo "--- Installing Docker Compose ---"
# Download Docker Compose
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
# Apply executable permissions
sudo chmod +x /usr/local/bin/docker-compose
# Change ownership (optional but good practice)
sudo chown "$USER" /usr/local/bin/docker-compose
echo "Docker Compose downloaded and permissions set."
# Verify Docker Compose installation
echo "Verifying Docker Compose installation:"
docker-compose --version
echo "Development environment setup complete!"
echo "Remember to log out and log back in (or reboot) to apply Docker group changes."
This final section downloads the Docker Compose binary, makes it executable, and sets its ownership. A verification step confirms the installation.
How to Run the Script
Save the script: Copy the entire script content into a file (e.g., setup_dev_env.sh).
Make it executable: Open your terminal and run:
chmod +x setup_dev_env.sh
Execute the script:
./setup_dev_env.sh
You will be prompted for your sudo password as needed.
Important: After the script finishes, remember to log out and log back in (or reboot your system) to ensure that your user's membership in the docker group takes effect.
Conclusion
With this script, you can quickly set up a powerful and consistent development environment on your Debian-based Linux machine, equipped with Rust, essential build tools, Docker, and Docker Compose. This automation saves time and reduces friction, letting you focus on what matters most: building amazing software!
Happy coding!
#Linux #Ubuntu #KaliLinux #Rust #Docker #DockerCompose #DevSetup #Automation #BashScripting
Top comments (0)