Puget Systems print logo
Read this article at https://www.pugetsystems.com/guides/1178
Dr Donald Kinghorn (Scientific Computing Advisor )

The Best Way To Install Ubuntu 18.04 with NVIDIA Drivers and any Desktop Flavor

Written on June 8, 2018 by Dr Donald Kinghorn

In this post I'll be going over details of Installing Ubuntu 18.04 including the NVIDIA display driver and, any one of the available desktop environments. I'll do this starting from a base server install. You'll be able to pick any desktop "flavor" you want -- I'll use MATE because I like it. I have found the method presented here to be the most likely to succeed no matter what hardware configuration you are installing onto.

A couple of weeks ago I did a post titled Install TensorFlow with GPU Support the Easy Way on Ubuntu 18.04 (without installing CUDA). One thing I did not cover in that post was how to install Ubuntu 18.04. I had mentioned that I would do a post on installing Ubuntu 18.04 and that I would go over an unofficial CUDA install. This post will be the first part of that. I might look at making CUDA 9.2 work on 18.04 in a later post. [My recommendation for setting up CUDA environments these days is to use Docker and NVIDIA-Docker which I have covered in other posts.]

In the title I said "The Best", that, of course, is subjective! Installing Linux can sometimes be frustrating especially if you are installing onto new "bleeding edge" hardware or something with an unusual configuration. Linux is usually very easy to install and configure but when it's not it can be very frustrating. The installation method I present here is, in general, my preferred method for installing Linux. In particular this post details how I nearly always install Ubuntu.

I have Ubuntu 18.04 on all of my Linux systems now and I like it a lot. It doesn't seem to be a big change from 16.04, it mostly feels more polished and stable. Some changes are subtle but very welcome. For example, it is the first Linux release that I have installed on a laptop and had all of the special function keys work correctly without any special effort.

Installing a Desktop with Ubuntu 18.04 from the "Server" base image

Yes, installing "server" first is my preferred way to setup a desktop.

Why install from server?

  • A minimal server install is fast, simple and allows configuration flexibility.

  • It's simple to add any desktop environment you want on top of server.

  • You can do (or even script) a complete install including adding proprietary display drivers before your first boot into desktop mode.

  • A server install is "usually" more likely to work if you are using "bleeding edge" hardware or unusual configurations.

That last reason is generally why I do it this way! I often have new/pre release hardware to test. I've installed Linux thousands of times, and that's not counting automated provisioning. I usually have best luck with installs by keeping things simple and then build on that.

Note! Installing from one of the desktop flavors live-media can be easy "when it works" and it often does work just fine. Hardware detection with the live media is usually very good. However, it's not as flexible and can sometimes be frustrating when trying to get propitiatory graphics drivers installed and working right. If you are doing a simple workstation (or laptop) install don't hesitate to try using a "desktop-live-media" image, it may work fine for you, but, if it doesn't, then knowing how to fall back to a simple base install can save you some grief and frustration.

Step 0) Prepare your hardware and make backups if needed.

I'm assuming that you are doing a clean install. If you have anything important on the disk(s) you are going to use for the install please make backups! If you have secondary drives or data drives that you want to preserve and use in the new install you could disconnect them during your fresh install so that you don't accidentally overwrite them. You can reattach and mount them in your new install later.

Step 1) Get Ubuntu

CAUTION! DO NOT USE THE DEFAULT Ubuntu 18.04 Server Download!!

The default download for Ubuntu 18.04 server gets you a new "live-server" installer. I don't really understand why they did that. It does not have as many options as the old installer and it doesn't allow for any special partitioning like RAID setup or any advanced networking. The worst problem with that default installer is, ...

The default Ubuntu 18.04 server download is for a cloud based install! It installs the Ubuntu cloud image and cloud configuration without any option to change that. It is not suitable for a "normal" install on your own hardware. What you want is called "Basic Ubuntu Server" and it is not available with this installer.

There is an "Alternative" installer which is the same as the standard installer from Ubuntu 16.04. I'll use the "alternative/standard" installer in this post.

You can get the Ubuntu server image from Canonical's site. They now only list 18.04 on the main download page and you don't want that download. The Alternative Downloads page has 16.04 LTS and other versions as well as the standard installer for use with 18.04. 16.04 is solid and well supported and will remain that way for several more years. If you use the HWE kernel it will work fine with recent hardware. However, I do recommend that you move to 18.04. It has only been out for a short time but it is already widely supported.

download page

alt installer

Step 2) Boot the install image in UEFI mode

I recommend you use UEFI for your install. If you have been doing this for a while you may be comfortable with legacy MBR installs but it's probably time to try UEFI if that is the case. If you are using new hardware some of it may not even work correctly if you don't boot to UEFI. Be sure you BIOS has "secure boot" disabled. You might be able to get your install to work with "secure boot" enabled but you will have mysterious errors when you try to install the NVIDIA driver kernel modules.

To start your install you will need to know the magic key to press at startup to get a boot device select screen. Unfortunately that's not standard among different motherboard manufacturers so you will need to look it up if you don't know what it is. When you get to that boot selection screen you may have a choice of boot partitions on the install device. One of them should be labeled UEFI. Use that.

Step 3.1) Proceed with the install

Note: if you start the install and have corrupted video then you may need to do what I suggest in Step 5) below to get the install started correctly.

Once you have started the install you will be guided though several question that will be pretty obvious ... until, you get to "Partition disks" ...

Step 3.2) Disk partitions

Unmount in-use partitions

If you are installing onto a disk that already has partitions on it the first thing you will see in the Partition disks section is the following,

umount partitions

You probably want to say "yes".

Easy partitioning

Next will be choosing how to do the partitions. If you are insatlling onto a single disk and especially if it is an SSD or NVMe drive then I recommend "use entire disk".

This is the first time ever that I have recommended using this option! In 18.04 this opttion does a reasonable thing for a single disk install with an SSD or NVMe drive.

use entire disk

Pick the disk you want to use and then you will get something like the following,

simple disk partitions

This will create a 512MB EFI partition for the UEFI boot information (/boot/efi is mounted there). The rest of the disk is allocated to the system root file system (/). This is really how you want to partition a modern SSD or NVMe drive!

What about a swap partition?

You don't need to create a swap partition. the installer will create and setup swap on a swap file. It creates a 2GB swapfile,

kinghorn@u18:~$ swapon --show
/swapfile file   2G   0B   -2

That's all you need! [If you do have some reason for more swap you can always make additional swap files of any size you want.]

Manual partitioning if you need it

If you don't like what I recommended above for any reason, like maybe you want to setup a RAID or you are using multiple disks or want to use LVM or something, then the you will be happy that the partitioning tool in the 18.04 installer is the same as it was for 16.04 i.e. it's pretty good. I am not going to cover that in this post. You might want to look at my post on installing Ubuntu 16.04 where I go over manual partitioning.

Initial Software selection

At this point the installation will will proceed with just a couple more simple questions. When you get to the "Software selection" screen I recommend that you add the OpenSSH server. You don't need to add anything else at this point since we will be doing a full desktop install after first boot.

Add ssh server

After this the install will finish and you will be ready for first boot into the OS.

Step 4) Potential problem number 1!

Hopefully you wont need this step!

You might need "nomodeset" until you get GPU drivers installed! You could have this problem during the install too. What I describe here will "usually" take care of this. It is one of the most common problems installing Linux on a system with an NVIDIA GPU installed.
When you reboot the system may come up into a corrupted screen or it may hang! This is because the proprietary driver is not installed for the NVIDIA card (which I presume you have in the system). This is most often caused by the system seeing your great video card and then trying to bring up a console in a "frame-buffer". RANT-ON There is no reason for that on a server install! ... RANT-OFF

Here's how you get around this if you encounter it,

When you get to the Grub selection screen type e That will let you edit the kernel boot parameter line (for this boot only). You need to find the line that starts "Linux" go to the end of that line and add nomodeset Then press F10 to boot. That should get you to a login screen. We will have everything installed including the NVIDIA driver before the next boot so this should be the only time you have to do this and there should be no reason to have to add nomodeset permanently.


nomodeset end

Step 5) Run updates, add your desktop of choice

Login to your system. Now we'll add the good stuff!

First run updates,

sudo apt-get update
sudo apt-get dist-upgrade

You may get a kernel update but don't reboot yet!

Select and install your desktop of choice

We will use a very handy command that is is installed by default with a server install (with the installer we used!).

sudo tasksel

With tasksel you you have a lot of options available. It's a really nice tool! The image below show some of the tasksel options. I have selected "Ubuntu MATE desktop". That's my current favorite Linux desktop.
tasksel image

Adding a desktop flavor will download and install a lot of packages so this may take awhile.

Don't reboot yet! We want to get the NVIDIA display driver installed BEFORE we boot to a GUI desktop.

Step 6) Install the NVIDIA display driver

There are a few methods for installing the proprietary NVIDIA display driver. For Ubuntu installs the one I recommend is to install the latest driver by adding the the graphics driver ppa repository. This is well maintained and you will be able to get the latest driver (or older ones if needed).

The command to add graphics-drivers ppa is,

sudo add-apt-repository ppa:graphics-drivers/ppa

Before you install the driver it is good to be certain dkms (dynamic kernel module support) and build-essentials is installed. This is because whenever the system kernel is updated dkms will automatically rebuild the NVIDIA driver module for the new kernel. It needs build tools and the kernel headers for this which will be installed with build-essential.

sudo apt-get install dkms build-essential

[ You could also add some other packages now if you like. Maybe the synaptic package manager... ]

Now to install the driver,

sudo apt-get update
sudo apt-get install nvidia-390

This installs the latest driver version 390 (as of this writing). That will work with NVIDIA Volta and lower cards.

This install should be robust. New kernels or drivers should automatically rebuild with dkms.

Now you can reboot!

sudo shutdown -r Now

When your system comes up you should be greeted with a graphical login manager running with the NVIDIA display driver. You will notice that you get a lot of messages on the screen during boot. That's because we installed from server. A typical desktop install from live media will be configured to hide all of that information from you. Personally I like to see it! You will sometimes see some warnings or errors. Those are almost always artifacts of startup ordering or some such no concerning events. However, if there is a real problem on the system those messages can give you useful information for diagnoses.

Step 7) Optional: enable NetworkManager

Ubuntu 18.04 has a new network setup using "netplan"!

Networking has changed in Ubuntu 18.04. It is now using a tool called "netplan". You can go read about on the netplan web site.

One artifact of doing an install from server is that the network interface that is configured during the install will be using "systemd-networkd" instead of NetworkManager. This is because the server install doesn't have NetworkManager! That's OK, but using NetworkManager is more common for a desktop install and it can be useful, especially for systems like laptops where there may be frequent interface switching. NetworkManager is a good system tool and it handles wifi well. You can switch your system to NetworkManager control with the following instructions.

netplan is configured in a "yaml" file in /etc/netplan/ The configuration file may have different names on different systems. On my install the file name is 01-netcfg.yaml

Lets make a backup copy of that yaml file and edit the existing one to use NetworkManager.

cd /etc/netplan
sudo cp 01-netcfg.yaml 01-netcfg.yaml-backup

Now edit 01-netcfg.yaml using your editor of choice (and use sudo). Change the file so it looks like,

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
  version: 2
  renderer: NetworkManager

Then run the following to make the new setup,

sudo netplan generate
sudo netplan apply

Lastly restart the NetworkManager service,

sudo systemctl restart NetworkManager.service

You are now using NetworkManager.

Ubuntu 18.04 is really a great distribution, enjoy!

Happy computing --dbk

Tags: Ubuntu 18.04, NVIDIA, Install
Avatar Machmer

hello Don,

I have followed the instructions and after rebooting at the end, for a moment tty1 appears and display goes no signal. You have any guess what might have gone wrong?
My configuration is i5-6700K, GTX1060 6G

Posted on 2018-06-15 08:02:42
Avatar Machmer

I found the issue with showing no signal on monitor had nothing to do with the driver, but with the xorg config. It seems the detected maximum resolution by GPU cannot be handled by my Monitor(which is a Toshiba 4K UHD) so display goes no signal.

I added following changes to the /etc/X11/xorg.conf under section Screen. finally everything works well. :)

Section "Screen"
Identifier "Default Screen"
Monitor "Configured Monitor"
Device "Configured Video Device"
DefaultDepth 24
SubSection "Display"
Depth 24
Modes "1920x1080"

also I used recovery mode and mounted the file system as Read-Write using

mount -o rw,remount /

then changed the Xorg config file/

Posted on 2018-06-16 15:14:42
Avatar jason seymour

looks like a great way to go but when i try to run after reboot i get a black screen. Asus fd503vx GTX1050 , i used nomodeset and pci=nomsi(the pci bit is the only part i can use to get any ubuntu to install

Posted on 2018-07-22 05:02:04
Avatar jason seymour

how to do this only connected via wifi, no network cable

Posted on 2018-07-22 05:21:55
Avatar Donald Kinghorn

I forgot to monitor this post! You will probably be best to try installing from the Live media. It will have more drivers loaded and will hopefully pick up your wifi card.

Installs can be a lot of trouble because there are so many variables. I usually have my best luck going with what I described in this post ... but it doesn't always work!
Best wishes --Don

Posted on 2018-08-01 21:23:30
Avatar Tom K.

Hi Don. Thanks for your very helpful article! Just thought you'd like to know about a little typo I noticed. In your first "Note" under "Installing a Desktop with Ubuntu...", instead of "propitiatory graphics drivers", I'm sure you meant to say "proprietary graphics drivers".

Posted on 2018-08-19 06:01:50
Avatar jason seymour

Worked great thank you for the new solution

Posted on 2018-08-23 00:39:43
Avatar Tom Cipollone

I followed everything in your instructions as far as I was able. Upon loading the cuda toolkit with "sudo sh cuda_9.2.148_396.37_linux.run" I followed all of the prompts and I always get "You are attempting to install on an unsupported configuration. Do you wish to continue?" I hit yes. After all of the other prompts, I get "The driver installation has failed due to an unknown error. Please consult the driver installation log located at /var/log/nvidia-installer.log."

I have done that which is described in the log file. Do you have any suggestions?

Thank You

Posted on 2018-08-27 04:34:17
Avatar Donald Kinghorn

... the thing to be careful about is the driver. In this post I'm installing the driver from the ppa and didn't do a CUDA install ... You are installing cuda 9.2 that will have a base 396.37 display driver for it's runtime. If you have installed a recent nvidia-396 from the ppa you should be OK and you can skip the driver install during the cuda install. That should work. Check out this post and the comments https://www.pugetsystems.co...

Posted on 2018-08-27 15:58:37
Avatar Donald Kinghorn

... Also, you may be getting an error message that you can ignore (?) If the toolkit installed under /usr/local/cuda then you should be able to ignore the error as long as you have the nvidia-396 driver installed.

NVIDIA is working on a new CUDA 9.3 build which should be released soon. I'm pretty sure that version will have a proper Ubuntu 18.04 installer in it.

Maintaining Development environments can be a pain! I'm getting more to where I use docker containers for dev environments when I need them but then you have to setup and maintain a docker environment :-)

Posted on 2018-08-28 15:58:38

Now that the new drivers are you, do you recommend using nvidia-driver-410 or nvidia-driver-415 from the mentioned PPA?

Posted on 2019-01-10 01:49:21
Avatar Donald Kinghorn

I would go with the 415 driver, just because it's newest. The big changes came in 410 but 415 is stable too with just a couple of small changes. I just tested with a couple of RTX Titans using 410 and it supported them fine but ID'd them as "Graphics Device" :-) 415 knows their name ...

Posted on 2019-01-10 17:01:32
Avatar archenroot

NOTE: Don't use this approach for TESLA drivers... the repos referenced here are only for GTX like cards...

Posted on 2019-03-09 07:28:17
Avatar Donald Kinghorn

I assume no one reading this is running a desktop on Tesla since that's not actually possible (no display out) :-) Just checked ... the NVIDIA driver pages lists a 410 driver for Tesla but the new CUDA 10.1 is using 418.39 so regardless of the GPU if you installed the driver from a full CUDA install that is what you would get. The ppa now has 418.43 as the latest. In general it doesn't mater (on Linux) as long as the driver supports the compute level of your GPU ... the CUDA runtime is from the display driver. I usually just try to use the latest driver (because I am usually testing the latest hardware)

I should note that I did run into a strange issue once with minor version number differences on display driver that was different between the CUDA package and the "normal" driver package. There is always a possibility of a gotcha! That's why I nearly always use the method in this post since I've found it to be the most likely to work ... and it's really fast ... and can be automated ... I've essentially done the same thing for cluster using both Tesla or GeForce cards. It's been a while since I've done any clusters though :-)

Cheers mate!

Posted on 2019-03-11 19:27:40
Avatar Drake

Hi Don - thanks for doing this! I had done a previous install with a mini.iso and am troubleshooting some issues with the 8400GS GeForce card. If you are open to questions, I have a few. 1) Do you see any advantage to using the server install over the mini.iso (I want to install a very basic LXDE desktop on a Dell Optiplex 790. I am a big fan of the old Lubuntu minimal desktop (when it was LXDE instead of LXQT) and am replicating that)? 2) I am thinking OpenSSH wouldn't be relevant for me....I generally choose nothing and then install LXDE-core after arriving at the command prompt following the initial install. Do you disagree? 3) I have been trying to get Nvidia 340 to work, but it is having some issues. It is recommended on the Nvidia site. Do you recommend using whatever is the latest or something different than the 340? I am finding that I don't get the Dell splash screen (monitors don't wake up until the boot arrives at the desktop) and windows seen to unfold rather than open.

I think that has it covered. Grateful for any thoughts you could throw my way if you are still monitoring this. Thanks!

Posted on 2019-10-21 01:29:48
Avatar Donald Kinghorn

Hi Drake ... no problem :-)
1) There are some advantages to going installing from server and your question 3 might be effected ?? ... In general it's OK to do the install any way that works :-) but, I get called in now and then for some strange install problems at work and usually going from server takes care of it. (or at least exposes what is actually causing trouble) That's my main reason for doing it. It's fast and usually works without trouble.

I here you about LXDE! I like a simple traditional desktop too. I use MATE (derived years ago from a gnome2 fork) MATE is pretty flexible these days but I set it up in the traditional (gnome2) way. ...I'll come back to this ...

2) You can leave off the openssh install. The ssh client installs by default it's the server that gets left out. So this is just a personal choice. I inevitably try to ssh into a machine and find out the server is not installed and get aggravated (even on Windows :-)

3) I think the display problem you are having is likely coming from GDM getting installed from the mini.iso (GDM gives us more trouble than anything else with Linux). Secondly, I think you can just use the latest NV driver with that 8400 ... I would use do the install from the ppa...

If you install from a "normal" Ubuntu iso (including the mini.iso --- which downloads everything fresh instead to updating from what is on the main iso) you will get GDM when X loads. Adding LXDE after that will probably just use GDM instead of loading LXDM.

When I do a MATE install I start from server and then use tasksel to install MATE that give me lightdm for X startup. This usually takes care of the missing display problem on startup. You can also install lightdm after the overall OS install and it should replace GDM as default.

I'm not completely sure about LXDM as a display manager?? If you have an install running with LXDE for desktop you might try doing apt-get install lxdm to see if lxdm is installed ... if not then install it to try to override GDM ...

If you want to start clean this is a case where I would recommend doing the server install and installing LXDE with tasksel. That way you will be sure to be getting a "pure" LXDE install setup.

Posted on 2019-10-21 16:35:47