Skip to main content

Editor Note: Pythonic employs a team of experts in engineering, AI, and machine learning. With their insights and expertise, Pythonic solutions simplify the complicated, applying cutting-edge AI to the title industry. This latest post highlights their knowledge and ongoing learning for the company and its clients.

If you've ever dived into the world of machine learning on Ubuntu 20.04 or later, you know that setting up CUDA can be like navigating a labyrinth, particularly with specific dependencies such as PyTorch, which ties to particular CUDA versions. After several frustrating attempts and combing through forums and documentation, I've finally cracked the code to install the correct CUDA version for my needs. Here are the steps that led to success.

Step 1: Download the right version of CUDA

The following are compatible on Ubuntu 20.04 or later:

  • wget
  • wget
  • wget
  • wget
  • wget
  • wget
  • wget
  • wget
  • wget
  • wget
  • wget
  • wget

Step 2: Execute a batch command to install all downloaded versions

Do the following to install all:

ls cuda*.run | awk '{print "sudo bash "$1" --no-drm --no-man-page --override --toolkit --silent"}' | sh


#sudo bash --no-drm --no-man-page --override --toolkit --silent

Step 3: Configure the virtual environment to use the expected CUDA version

Now let’s do the final setting to make sure my virtualenv is using the right CUDA version. As an example, let’s choose to use CUDA 11.1. I just simply add the following two lines to my virtualenv/bin/activate:

vim virtualenv/bin/activate

export PATH=/usr/local/cuda-11.1/bin:$PATH

export LD_LIBRARY_PATH=/usr/local/cuda-11.1/lib64:$LD_LIBRARY_PATH

Now when I run 


to start my virtual environment, and do “nvcc –version”, I should have:

nvcc: NVIDIA (R) Cuda compiler driver

Copyright (c) 2005-2020 NVIDIA Corporation

Built on Mon_Oct_12_20:09:46_PDT_2020

Cuda compilation tools, release 11.1, V11.1.105

Build cuda_11.1.TC455_06.29190527_0

And if I deactivate the virtual environment, and I run “nvcc –version”, it happens that I don’t have the default nvcc, so Ubuntu complains that I should install nvidia-cuda-toolkit first:

Command 'nvcc' not found, but can be installed with:

apt install nvidia-cuda-toolkit

Please ask your administrator.

So it’s very certain that I have the CUDA installed and it could be tied to a specific virtual environment. 

Additional Note

Please be aware that nvidia-smi gives you the CUDA driver for GUI-related applications. It could be the same as the CUDA version you just installed or very different. As a matter of fact, we installed multiple versions of CUDA. It took me quite a while to realize the CUDA version used by nvidia-smi could be different from the one on my terminal.

Dr. Baoqiang Cao
Post by Dr. Baoqiang Cao
Jun 10, 2024 10:52:42 AM
Pythonic Co-Founder and CTO: Bao is an entrepreneur who’s passionate about AI and has deep knowledge of various industries. He developed the core AI algorithms that powered Networked Insights prior to the company’s acquisition by American Family Insurance in 2017. Bao received his Ph.D. from the University of Cincinnati with post-doctoral work at the University of Nebraska and University of Texas at Austin.