Skip to content

Instantly share code, notes, and snippets.

@sbmaggarwal
Created July 31, 2025 06:05
Show Gist options
  • Save sbmaggarwal/0da09e8ab6d8d872d0fa023e5f76b8f9 to your computer and use it in GitHub Desktop.
Save sbmaggarwal/0da09e8ab6d8d872d0fa023e5f76b8f9 to your computer and use it in GitHub Desktop.
Fully automated Linux VM setup script to install essential tools including Git, Docker, Java 17, Python, Node.js, RDP access, and more. Ideal for developer workstations or cloud VM bootstrapping with minimal prompts.
#!/bin/bash
set -e
echo "πŸ› οΈ Starting Linux VM setup..."
# Function to prompt user with Y/n question
prompt_yes_no() {
local prompt_message="$1"
local default_answer="${2:-Y}"
read -p "$prompt_message [Y/n]: " input
input="${input:-$default_answer}"
[[ "$input" =~ ^[Yy]$ ]] && return 0 || return 1
}
# Step 1: Update and upgrade
echo "πŸ”„ Updating and upgrading apt packages..."
sudo apt update && sudo apt upgrade -y
# Step 2: Install common CLI tools
echo "πŸ“¦ Installing basic tools (curl, wget, unzip, htop)..."
sudo apt install -y curl wget unzip htop gnupg lsb-release software-properties-common apt-transport-https ca-certificates
# Step 3: Git
if prompt_yes_no "Do you want to install Git?" "Y"; then
sudo apt install -y git
fi
# Step 4: Python
if prompt_yes_no "Do you want to install Python 3 and pip?" "Y"; then
sudo apt install -y python3 python3-pip
fi
# Step 5: Java 17
if prompt_yes_no "Do you want to install OpenJDK 17?" "Y"; then
sudo apt install -y openjdk-17-jdk
echo "βœ… Java version:"
java -version
fi
# Step 6: Docker
if prompt_yes_no "Do you want to install Docker and Docker Compose?" "Y"; then
echo "πŸ“¦ Installing Docker..."
curl -fsSL https://get.docker.com | sudo bash
sudo usermod -aG docker $USER
echo "πŸ“¦ Installing Docker Compose plugin..."
DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker}
mkdir -p $DOCKER_CONFIG/cli-plugins
curl -SL https://github.com/docker/compose/releases/download/v2.27.0/docker-compose-linux-x86_64 -o $DOCKER_CONFIG/cli-plugins/docker-compose
chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose
echo "βœ… Docker version:"
docker --version
docker compose version
fi
# Step 7: Node.js (LTS)
if prompt_yes_no "Do you want to install Node.js LTS and npm?" "Y"; then
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt install -y nodejs
echo "βœ… Node version:"
node -v
fi
# Step 8: Build-essential
if prompt_yes_no "Do you want to install GCC and development tools (build-essential)?" "Y"; then
sudo apt install -y build-essential
fi
# Step 9: xRDP and XFCE
if prompt_yes_no "Do you want to install xRDP for remote desktop access?" "Y"; then
sudo apt install -y xrdp
if prompt_yes_no "Install XFCE as the desktop environment?" "Y"; then
sudo apt install -y xfce4 xfce4-goodies
echo "xfce4-session" > ~/.xsession
sudo systemctl enable xrdp
sudo systemctl restart xrdp
fi
echo "βœ… xRDP is ready. Connect via RDP on port 3389."
fi
# Step 10: Print IPs
echo "🌐 Fetching IP addresses..."
PUBLIC_IP=$(curl -s ifconfig.me || echo "Unavailable")
INTERNAL_IP=$(hostname -I | awk '{print $1}')
echo ""
echo "====================================="
echo "βœ… VM Setup Completed Successfully!"
echo "πŸ“ Internal IP Address: $INTERNAL_IP"
echo "🌍 Public IP Address: $PUBLIC_IP"
echo "====================================="
echo ""
echo "⚠️ Please reboot the machine or logout and login again for changes like Docker group to apply."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment