How to modify Cuda, GCC, python versions in colab

Ajith Kumar V
2 min readApr 16, 2023

--

This blog post will guide you through the process of modifying CUDA, GCC, and Python versions in Google Colab. As of April 2023, Colab uses CUDA version 12.0 and Python version 3.9 by default. If you need to downgrade these versions, this notebook will help you do so.

When working with certain deep learning repositories, the CUDA version, GCC version, Python version, and PyTorch version may be interdependent. For example, CUDA 10.2 only supports specific GCC versions, and some lower versions of PyTorch can only be installed on Python 3.6 and 3.7

Installing CUDA 10.2 in colab

!wget https://developer.download.nvidia.com/compute/cuda/10.2/Prod/local_installers/cuda-repo-ubuntu1804-10-2-local-10.2.89-440.33.01_1.0-1_amd64.deb
!dpkg -i cuda-repo-ubuntu1804-10-2-local-10.2.89-440.33.01_1.0-1_amd64.deb
!apt-key add /var/cuda-repo-10-2-local-10.2.89-440.33.01/7fa2af80.pub
!apt-get update
!apt-get install cuda-10-2
!export CUDA_PATH=/usr/local/cuda-10.2/
!nvcc --version

if you want any other version of CUDA you can go to archives in Nvidia site https://developer.nvidia.com/cuda-10.2-download-archive and you can change the first 5 lines above.

Installing GCC 7.5.0

!sudo apt-get update && \
sudo apt-get install build-essential software-properties-common -y && \
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y && \
sudo apt-get update && \
sudo apt-get install gcc-7 g++-7 -y && \
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 70 --slave /usr/bin/g++ g++ /usr/bin/g++-7 && \
gcc -v
!sudo apt-get install gcc-7 g++-7 g++-7-multilib gfortran-7
!sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 70 --slave /usr/bin/g++ g++ /usr/bin/g++-7
!sudo update-alternatives --config gcc
!gcc --version

Now GCC version would be 7.5.0

Installing Python 3.7

!apt-get install python3.7
!apt-get update -y
!update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 1
!update-alternatives --config python3
# select python version
!apt install python3-pip
!apt install python3.7-distutils
!python --version

Replace 3.7 with version of python you need

Install torch==1.2, torchvision==0.4.0

!pip install torch==1.2
!pip install torchvision==0.4.0

Colab notebook can be found here and github is here .

--

--