Software & AppsOperating SystemLinux

How To Fix “Unsupported Compiler Version” Error When Installing CUDA on Ubuntu 20.04

Ubuntu 21

When installing CUDA on Ubuntu 20.04, you may encounter an “unsupported compiler version” error. This typically happens when the version of the gcc compiler installed on your system is not compatible with the CUDA version you’re trying to install. In this article, we will guide you through the steps to fix this error.

Quick Answer

To fix the "unsupported compiler version" error when installing CUDA on Ubuntu 20.04, you need to install gcc version 8 and update the gcc and g++ alternatives to use version 8. After that, you can run the CUDA installation command with the –override argument to force the installation. Finally, add the necessary symlinks for CUDA and update your PATH and LD_LIBRARY_PATH environment variables.

Prerequisites

Before we start, make sure you have downloaded the CUDA installation runfile from the official Nvidia website.

Step 1: Make the Runfile Executable

Open a terminal and navigate to the directory where the runfile is located. Run the following command to make the runfile executable:

chmod +x cuda_10.2.89_440.33.01_linux.run

In this command, chmod +x is used to change the permission of the file and make it executable. The cuda_10.2.89_440.33.01_linux.run is the name of the runfile you downloaded from the Nvidia website.

Step 2: Install GCC-8

CUDA 10.2 requires gcc version 8. To install it, run the following command:

sudo apt install gcc-8

The sudo command is used to run the command as the root user, apt install is used to install new packages, and gcc-8 is the package name for the gcc version 8.

Step 3: Update GCC and G++ Alternatives

Next, update the gcc and g++ alternatives to use version 8 by running the following commands:

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 8
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-8 8

The update-alternatives command is used to maintain symbolic links determining default commands. The --install option is used to add a group of alternatives to the system. /usr/bin/gcc and /usr/bin/g++ are the master links, gcc and g++ are the names of their groups, /usr/bin/gcc-8 and /usr/bin/g++-8 are the paths to the alternative versions, and 8 is the priority of the alternatives.

Step 4: Verify the GCC Version

To verify that the gcc version has been updated, run:

gcc -v

The output should show the installed version as 8.x.x.

Step 5: Run the CUDA Installation Command

Now, run the CUDA installation command with the --override argument to force the installation:

sudo sh cuda_10.2.89_440.33.01_linux.run --override

The --override option forces the installer to ignore the unsupported compiler error and proceed with the installation.

Step 6: Check the Installation Log

If the installation fails, you can check the log file for more details by running:

cat /var/log/cuda-installer.log

Step 7: Add Necessary Symlinks for CUDA

To add the necessary symlinks for CUDA, run the following commands:

sudo ln -s /usr/bin/gcc-8 /usr/local/cuda-10.1/bin/gcc
sudo ln -s /usr/bin/gcc-ar-8 /usr/local/cuda-10.1/bin/ar
sudo ln -s /usr/bin/gcc-ranlib-8 /usr/local/cuda-10.1/bin/ranlib
sudo ln -s /usr/bin/gcc-nm-8 /usr/local/cuda-10.1/bin/nm

The ln -s command is used to create symbolic links. This step ensures that CUDA uses the correct version of gcc.

Step 8: Update Your PATH and LD_LIBRARY_PATH

Update your PATH environment variable to include the CUDA binaries by adding the following line to your .profile or .bashrc file:

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

Update your LD_LIBRARY_PATH environment variable to include the CUDA libraries by adding the following line to your .profile or .bashrc file:

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

The export command sets the environment variables. PATH is used to specify directories where executable programs are located, and LD_LIBRARY_PATH is used to specify directories where libraries should be searched for first.

Step 9: Apply the Changes

Save the file and run the following command to apply the changes:

source ~/.profile

The source command reads and executes commands from the file specified as its argument in the current shell environment.

Conclusion

Now, you should be able to run the make files on the CUDA samples and get a working demo. If you encounter any further issues, please provide more details for further assistance. This process should help you to overcome the “unsupported compiler version” error when installing CUDA on Ubuntu 20.04.

Can I install CUDA on Ubuntu 20.04 without updating the gcc version?

No, CUDA requires a specific version of gcc for compatibility. Updating the gcc version is necessary to fix the "unsupported compiler version" error.

Where can I download the CUDA installation runfile?

You can download the CUDA installation runfile from the official Nvidia website at https://developer.nvidia.com/cuda-downloads.

What if I already have a different version of gcc installed on my system?

It is recommended to install the required gcc version (in this case, gcc-8) alongside your existing version. You can have multiple versions of gcc installed simultaneously without conflicts.

How can I check the current version of gcc installed on my system?

You can check the current version of gcc by running the command gcc -v in the terminal. The output will display the installed version.

What should I do if the CUDA installation fails despite following the steps?

If the installation fails, you can check the installation log file for more details. Run the command cat /var/log/cuda-installer.log to view the log and troubleshoot the issue.

Do I need to update my PATH and LD_LIBRARY_PATH environment variables after CUDA installation?

Yes, updating the PATH and LD_LIBRARY_PATH environment variables is necessary to ensure that CUDA is correctly detected and utilized by your system. Follow the steps mentioned in the article to update these variables.

Can I use a different version of CUDA with this fix?

Yes, you can apply a similar fix for other versions of CUDA by adjusting the corresponding version numbers in the commands and paths mentioned in the article. However, make sure to check the specific requirements for the CUDA version you intend to install.

Leave a Comment

Your email address will not be published. Required fields are marked *