You can install the latest version of Nvidia driver for your GPU in three easy steps given below. I have tested these on Ubuntu but they may work on other flavors of Linux too.
If you already know your Nvidia hardware model you can skip to step 2.
Step 1: Get to know your Nvidia Hardware name (mine is Nvidia Geforce 940MX), by executing the following
lshw -numeric -class display
Read the description should say "3D controller" that’s where nvidia is. Note the name of the product in bracket, mine was Geforce940MX
Step2: Once you know the name of your hardware, go to the nvidia website (http://www.nvidia.co.uk/Download/index.aspx) and select your driver, in the operating system, scroll down to select "All operating system", make sure you all checkboxes have the right details and operating system is linux, click on search. In the next page you will get information something like this
Version: 384.98
Release Date: 2017.11.2
Operating System: Linux 64-bit
Language: English (UK)
File Size: 77.23 MB
Note the Version number before the decimal, its 384 in my case.
Step 3: Proceed with installing the Nvidia driver by executing command sudo apt-get install nvidia-384 (note 384 is my version for Nvidia 940MX, yours maybe different).
After install nvidia drivers, you may also want to install the CUDA toolkit.
Step 1: Download the Nvidia CUDA toolkit , I had to download 7.5 (https://developer.nvidia.com/cuda-75-downloads-archive) due to some program requirement, you may download the newer version if you want. The CUDA 7.5 is not available for Ubuntu 16/17, you can still download the Ubuntu 15 version and it works perfectly on 16/17 too.
Step 2: To install CUDA driver, we need to shutdown the X Server(The ubuntu GUI), so I advice you to open these instructions on a mobile browser before proceeding as the GUI will close and a terminal like screen will appear after applying this command.
sudo service lightdm stop
Now you are in a black screen, press ALT+CTRL+F1-F7 to bring the terminal input screen, after you get the input screen. You can enter the following command to install the Nvidia driver.
sudo ./cuda_7.5.18_linux.run -extract=~/Downloads/Nvidia
This will extract the files into nvidia folder.
Step 3: Next go to the extracted folder(Downloads/Nvidia) and execute the following commands.
sudo ./cuda-linux64-rel-7.5.18-19867135 (The digits after cuda-linux64-rel may vary for your cuda version)
sudo ./cuda-samples-linux-7.5.18-19867135
Follow the on screen instructions to install both the cuda linux toolkit and the cuda samples. This will install cuda tool kit and samples in default location /usr/local/cuda-7.5
Step 4: Edit your system wide environment variable to set the paths for CUDA
sudo nano /etc/environment
Paste this please note the actual paths may vary for your configuration. These are default paths for CUDA 7.5
PATH=/usr/local/cuda-7.5/bin:$PATH
LD_LIBRARY_PATH=/usr/local/cuda-7.5/lib64:$LD_LIBRARY_PATH
Step 5: CUDA installation is done at this stage, time to test nvidia driver with CUDA by running a sample.
Go to the folder
cd /usr/local/cuda-7.5/samples/1_Utilities/deviceQuery
Execute sudo make, this will build the deviceQuery file. Run the file
./deviceQuery
This should show "Result: Success" at the end. If it does, congratulations Nvidia Driver and CUDA toolkit has been installed successfully. If it doesn’t you may need to follow this tutorial https://kislayabhi.github.io/Installing_CUDA_with_Ubuntu/ for common issues.
.