Install CUDA Toolkit 10.2 on Ubuntu 18.04.3
Official Document [link]
In fact, the official document is elaborated, however, somehow I failed to install it several times. So I recorded exact steps what I have done, FYI.
Installation
Step 1. Pre-installation Actions
In this step, please check whether your system is cuda-supported.
Note:
- gcc version is important, please refer to Table 1 in the link. Recommend: gcc-7.
- See Error case 1 to check and set default gcc version.
- When downloading cuda-toolkit, recommend to use
runfile(local), because for some reason, I trieddeb(local)anddeb(network), both failed.
Step 2. Package Manager Installation
If you use runfile(local), then there is no need to Install repository meta-data and Installing the CUDA public GPG key. You can directly execute:
1 | sudo apt-get update |
If the installation is broken, try:
1 | sudo apt --fix-broken install |
Step 3. Check installation
You can check whether you have successfully installed cuda by:
1 | nvidia-smi |
Then you will get something like this:
1 | +-----------------------------------------------------------------------------+ |
Step 4 Set environment variables
The PATH variable needs to include /usr/local/cuda-10.2/bin and /usr/local/cuda-10.2/NsightCompute-
To add this path to the PATH variable:
1 | $ export PATH=/usr/local/cuda-10.2/bin:/usr/local/cuda-10.2/NsightCompute-2019.1${PATH:+:${PATH}} |
In addition, when using the runfile installation method, the LD_LIBRARY_PATH variable needs to contain /usr/local/cuda-10.2/lib64 on a 64-bit system, or /usr/local/cuda-10.2/lib on a 32-bit system
To change the environment variables for 64-bit operating systems:
1
2export LD_LIBRARY_PATH=/usr/local/cuda-10.2/lib64\
${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}To change the environment variables for 32-bit operating systems:
1
2export LD_LIBRARY_PATH=/usr/local/cuda-10.2/lib\
${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
Error cases
1. Modify default gcc version
Step 1. Install different gcc versions using apt-get, for example:
1 | sudo apt-get install gcc-4.8 |
1 | sudo apt-get install gcc-7 |
Step 2. Check if gcc is installed successfully:
1 | gcc --verison |
or
1 | gcc-7 --version |
Step 3. Check priority of gcc
1 | sudo update-alternatives --config gcc |
You can see something like this:
1 | There are 2 choices for the alternative gcc (providing /usr/bin/gcc). |
Step 4. Modify priority of gcc
1 | sudo update-alternative --install /usr/bin/gcc gcc /usr/bin/gcc-7 100 |
Then you can see the priority of gcc-7 is set to be 100. You can check using the command in Step 3.
2. Sub-process /usr/bin/dpkg returned an error code (1)
1 | cd /var/lib/dpkg/ |