1
0

ml-setup.sh 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/bin/bash
  2. set -e
  3. echo "======================================"
  4. echo "🚀 Machine Learning Setup for Ubuntu 22.04"
  5. echo "======================================"
  6. # Update and upgrade
  7. echo "🔄 Updating system..."
  8. sudo apt update && sudo apt upgrade -y
  9. # Base tools
  10. echo "🛠️ Installing base development tools..."
  11. sudo apt install -y build-essential software-properties-common \
  12. git curl wget unzip zip ca-certificates gnupg lsb-release \
  13. python3 python3-pip python3-venv
  14. # Add deadsnakes PPA for latest Python versions (optional)
  15. # sudo add-apt-repository ppa:deadsnakes/ppa -y
  16. # sudo apt install -y python3.10 python3.10-venv python3.10-dev
  17. # Python packages
  18. echo "🐍 Installing Python ML packages..."
  19. python3 -m pip install --upgrade pip
  20. pip3 install numpy pandas scipy matplotlib seaborn scikit-learn jupyterlab \
  21. jupyter tensorflow torch torchvision torchaudio \
  22. transformers datasets keras opencv-python tqdm \
  23. xgboost lightgbm nltk spacy flask fastapi uvicorn
  24. # Jupyter config
  25. echo "📓 Setting up Jupyter..."
  26. jupyter notebook --generate-config
  27. # Optionally install Anaconda (comment out if not needed)
  28. read -p "Do you want to install Anaconda? (y/n): " install_anaconda
  29. if [[ "$install_anaconda" == "y" ]]; then
  30. echo "📦 Downloading Anaconda installer..."
  31. wget https://repo.anaconda.com/archive/Anaconda3-2024.02-1-Linux-x86_64.sh -O ~/anaconda.sh
  32. bash ~/anaconda.sh -b -p $HOME/anaconda3
  33. eval "$($HOME/anaconda3/bin/conda shell.bash hook)"
  34. conda init
  35. echo "✅ Anaconda installed and configured"
  36. fi
  37. # NVIDIA Drivers + CUDA (optional, only if you have NVIDIA GPU)
  38. read -p "Do you want to install NVIDIA drivers and CUDA? (y/n): " install_nvidia
  39. if [[ "$install_nvidia" == "y" ]]; then
  40. echo "🎮 Installing NVIDIA drivers and CUDA..."
  41. sudo apt install -y nvidia-driver-535
  42. sudo reboot
  43. fi
  44. # Docker + NVIDIA Container Toolkit
  45. read -p "Do you want to install Docker and NVIDIA Docker support? (y/n): " install_docker
  46. if [[ "$install_docker" == "y" ]]; then
  47. echo "🐳 Installing Docker..."
  48. sudo apt install -y docker.io
  49. sudo systemctl enable docker
  50. sudo usermod -aG docker $USER
  51. echo "💡 Installing NVIDIA Container Toolkit..."
  52. distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
  53. curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
  54. curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | \
  55. sudo tee /etc/apt/sources.list.d/nvidia-docker.list
  56. sudo apt update
  57. sudo apt install -y nvidia-container-toolkit
  58. sudo systemctl restart docker
  59. fi
  60. # Clean up
  61. echo "🧹 Cleaning up..."
  62. sudo apt autoremove -y
  63. sudo apt clean
  64. echo "✅ Machine Learning environment setup is complete!"
  65. echo "👉 Please reboot your machine if NVIDIA drivers were installed."