If you want to take advantage of a Nvidia GPU, then you need to install CUDA.

  • Ubuntu Anaconda

    Windows Native

    Not suggested.

    Windows Subsystem for Linux (WSL)

    Windows Subsystem for Linux is a Windows feature that enables users to run native Linux applications, containers and command-line tools directly on Windows 11 and later OS builds.

Step 1 - Install NVIDIA Driver for GPU Support

Download and install NVIDIA display driver on your Windows 11 system from the link:

  • https://developer.nvidia.com/cuda/wsl/download :::info This is the only display driver you need to install. However, you still need to install the CUDA toolkit in WSL. :::

    Step 2 - Install WSL 2 and then restart

    You can install everything you need to run Windows Subsystem for Linux (WSL) by entering the following command in an administrator PowerShell or Windows Command Prompt:
    1. wsl --install
    This command will enable the required optional components, download the latest Linux kernel, set WSL 2 as your default, and install a Linux distribution for you.
    You then restart your machine. :::info By default, WSL 2 comes installed with Ubuntu. Other distros are available from the Microsoft Store. :::

    Step 3 - Install CUDA Toolkit in WSL 2

    In order to compile a CUDA application on WSL 2, you will have to install the CUDA toolkit for Linux from the WSL prompt.

Launch WSL 2, then download the CUDA toolkit from the following link:

For example, CUDA toolkit 11.3.0 WSL-Ubuntu could be installed with the following commands:

  1. wget https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-wsl-ubuntu.pin
  2. sudo mv cuda-wsl-ubuntu.pin /etc/apt/preferences.d/cuda-repository-pin-600
  3. wget https://developer.download.nvidia.com/compute/cuda/11.3.0/local_installers/cuda-repo-wsl-ubuntu-11-3-local_11.3.0-1_amd64.deb
  4. sudo dpkg -i cuda-repo-wsl-ubuntu-11-3-local_11.3.0-1_amd64.deb
  5. sudo apt-key add /var/cuda-repo-wsl-ubuntu-11-3-local/7fa2af80.pub
  6. sudo apt-get update
  7. sudo apt-get -y install cuda

Alternatively, you can install CUDA toolkit using the anaconda package manager:

  1. conda install cudatoolkit=<version>

We suggest you install the CUDA toolkit using anaconda, as it enables you to have multiple environments, also anaconda will take care of dependencies issues within each environment. :::info According to CUDA on WSL documentation, OpenGL is not available on WSL at the moment. :::

Linux

We only cover Ubuntu here, however the steps should be similar for other Linux distributions.

First of all, you need to uninstall existing CUDA or cuDNN (if any):

  1. sudo apt-get remove --purge nvidia*

Switch to Nvidia graphics driver

In Ubuntu’ user interface, open Software & Updates, under the Additional Driverslabel, select a Nvidia official driver (i.e. Using NVIDIA driver metapackage from nvidia-driver-<version_number>), then restart the computer.software & updates.png

Update software list

  1. sudo apt update
  2. sudo apt upgrade

Install CUDA

Install CUDA from the Official website.
If you see Existing package manager installation of the driver found., you should select continue, because the old driver has been uninstalled in the previous step.
At the CUDA installerwindow, you should unselect Driveroption.

Configure environmental variable (for cuda 10.2)

  1. nano ~/.bashrc

Append the following command to that file:

  1. export PATH=$PATH:/usr/local/cuda-10.2/bin
  2. export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-10.2/lib64
  3. export CUDADIR=/usr/local/cuda-10.2

Then make it take effect:

  1. source ~/.bashrc

You should now be able to check the CUDA toolkit info using the command: nvcc -V.


配置国内镜像软件源(Mainland China only)

“Across the Great Wall we can reach every corner in the world”

首先,安装vim编辑器:

  1. sudo apt install vim

:::info 一键设置国内源 与 手动更改国内源 二选一即可。 :::

一键设置国内源

清华大学提供的切换国内源脚本:

  1. wget https://tuna.moe/oh-my-tuna/oh-my-tuna.py
  2. # For yourself
  3. python oh-my-tuna.py
  4. # ...or for everyone!
  5. sudo python oh-my-tuna.py --global
  6. # Get some help
  7. python oh-my-tuna.py -h

手动更改国内源

备份原来的源

  1. sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

更改源

  1. sudo vim /etc/apt/sources.list

内容为:

  1. deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
  2. deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
  3. deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
  4. deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
  5. deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
  6. deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
  7. deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
  8. deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
  9. deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
  10. deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

:::tips 注:按esc->:->wq退出 :::


完成以上步骤后记得更新软件列表:

  1. sudo apt update
  2. sudp apt upgrade

References