How do I Install CUDA on Ubuntu 18.04?
Solution 1
I have installed CUDA 9.1 on Ubuntu 18.04, and runs very well.
I modify THE default gcc and g++, and use .run
files instead of .deb
files.
-
Install gcc-6, g++-6 (CUDA requires gcc-6 !)
-
In
/usr/bin
runsudo rm gcc, gcc-ar, gcc-nm, gcc-ranlib g++ sudo ln -s gcc-6 gcc sudo ln -s gcc-ar-6 gcc-ar sudo ln -s gcc-nm-6 gcc-nm sudo ln -s gcc-ranlib-6 gcc-ranlib sudo ln -s g++-6 g++
-
Install CUDA using
.run
files. Installing the latest driver (if required, download NVIDIA-Linux-xxxxxxx.run from Nvidia) would be better.
That's all.
I've tried to install using .deb
files, but it causes package conflicts so I've switched to using this way.
Enjoy it!!
Solution 2
In a terminal, type:
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt update
sudo ubuntu-drivers autoinstall
reboot
sudo apt install nvidia-cuda-toolkit gcc-6
nvcc --version
I have a gtx970 graphics card and a fresh install of Ubuntu 18.04
This worked for me
Solution 3
Enable multiverse repository, install nvidia drivers and nvidia-cuda-toolkit and gcc6 (preferably using update-alternatives to easily switch versions):
- In software & updates, select the restricted and multiverse repositories
- In the Additional Drivers tab in software & updates select the NVIDIA proprietary driver (390 for CUDA 9)
- sudo apt update && sudo apt install nvidia-cuda-toolkit, or install it from the ubuntu software center.
- CUDA requires gcc6, use update-alternatives to maintain both gcc7 and gcc6 as explained here.
Alternatively you can follow Taylor's instructions:
- After installing the proprietary NVIDIA driver, download CUDA 9 installation from their site (get Ubuntu the 17.04 runfile version)
- make the downloaded file executable with
sudo chmod +x
- run it with --override flag
- Accept the terms and conditions, say yes to installing with an unsupported configuration, and no to “Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 384.81?”. Make sure you don’t agree to install the new driver.
- See above about using gcc6
The second method has the downside that it's not as easy to upgrade or remove.
Solution 4
I doubt the answers above qualify, because they seem to leave the system without the whole NVidia driver subsystem. I can guess why Cuda does not pull in the drivers, although I would probably prefer to have it otherwise. I am also not sure which is the proper way to get the latest driver, but right now this seems to do it:
sudo apt-get install nvidia-driver-390
Solution 5
The CUDA toolkit finally released the 18.04 ubuntu support
Related videos on Youtube
Gabs
~"If you are depressed, you are living in the past. If you are anxious, you are living in the future. If you are at peace, you are living in the present."~ - Lao Tzu
Updated on September 18, 2022Comments
-
Gabs over 1 year
Is there any tutorial to install CUDA on Ubuntu 18.04?
The instructions on the Nvidia website for 17.04 and 16.04 do not work for 18.04.
I get a message telling me to reboot then re-run the installer. However when I do this I get that same message again.
-
user3667089 about 6 yearsIt worked for me. Which part of it doesn't work for you?
-
Gabs about 6 yearsIt says that a reboot is need and then re-run the installer, but I reboot the computer and try to reinstall and all I get is the same message...
-
taper over 5 yearsTry follow the instruction here which uses the runfile to install the driver and the cuda toolkit.
-
-
Eliah Kagan about 6 yearsAlthough the link to the package page is useful, and there is enough information here that this isn't a "link-only answer" or anything, I do recommend that you edit this to explain how to do what you are recommending.
-
ubfan1 about 6 yearsRight, if you don't install the Nvidia drivers from the Ubuntu repositories, you may have to reinstall them after every kernel update.
-
Mr.WorshipMe about 6 yearsI recommend using update-alternatives instead of replacing gcc, see askubuntu.com/questions/26498/choose-gcc-and-g-version for more details
-
Mr.WorshipMe about 6 yearsYou probably also need nvidia-driver-390-dev
-
luboskrnac over 5 yearsThis should be accepted answer
-
salotz over 5 yearsGood answer, but in my situation the Ubuntu repo nvidia driver was the wrong sub-version! At the time of posting this the
nvidia-396
package is version 396.37 which doesn't work for my GeForce GTX 950. So I had to install 396.18 manually! So be sure to check the driver is the one you really need. -
Volkan Paksoy over 5 yearsThis mostly worked for me. Only problem was ubuntu-drivers was not found and had to fix it by running: sudo apt-get install ubuntu-drivers-common (found it here: askubuntu.com/a/361868/766963)
-
Alex Reinking over 5 yearsThis worked for me, though I had to switch back to nouveau from the UI before running autoinstall (it reported conflicts installing v396 while v390 was installed)
-
Luis over 5 yearsThis worked perfectly. However
sudo apt upgrade
broke everything again, be careful with upgrades! -
MrMartin about 5 yearsFor me, the
autoinstall
command results inThe following packages have unmet dependencies: nvidia-driver-415
-
loscuropresagio about 5 yearsA part from some unmet dependencies in autoinstall, this worked fine for me. Should definitely be the accepted answer.
-
mitchus about 5 yearsworked perfectly on 18.04
-
bhnn about 5 yearsThis worked perfectly for u18.04 and a nvidia 840M. I'm confused though, the question was "How do you install CUDA?": Is the above answer really everything from docs.nvidia.com/cuda/cuda-installation-guide-linux/… condensed into those 2 steps of
update drivers
andinstall cuda toolkit
or is this just the preparation to make sure the official installation guide works properly? -
dirac3000 almost 5 yearsNote it installed CUDA9.1 for me with a gtx970.
-
Alex Chan almost 5 yearsthis answer is awesome!
-
MJimitater almost 4 yearsIf I want to test this installation by running the CUDA samples, of course nvcc isn't found at
/usr/local/cuda/bin/nvcc
, sind apt-get installs it in/usr/bin/nvcc
. Is a soft link sufficient? EDIT: Just tried it, created a softlink atusr/local/cuda/bin/nvcc
(had to create directories first), and it worked!! Can't believe it actually -
Eric Wiener over 3 yearsI love you (also btw this installed CUDA9.1 for me)
-
Eric Wiener over 3 yearsIf you get the error,
sudo: ubuntu-drivers: command not found
, runsudo apt-get install ubuntu-drivers-common
. If you then get the errorE: Unable to correct problems, you have held broken packages.
, runsudo apt update && sudo apt-get upgrade -y
-
vidstige over 2 yearsThis should be the accepted answer