Provide a comprehensive guide for installing a Linux distro alongside Windows (dual boot) and setting up all necessary Nvidia drivers/libaries. It also follows a virtual enviroment paradigm for handling Python packages and creating environments with different independecies like different Python, CUDA, PyTorch/TensorFlow/NumPy/SciPy/matplotlib etc. versions.
This guide was tested on the following environment:
- PC
- Laptop: HP Omen 16-b1007nv
- CPU: Intel i7-12700H
- GPU: NVIDIA GeForce RTX 3070 Ti Laptop GPU
- RAM: 32 GB
- Disk: 1 TB
- OS: Windows 11 Business (21H2), Ubuntu Desktop 22.04.3 LTS
While UEFI Secure Boot is supported by Ubuntu, some issues still may rise like not be able to install some 3rd party kernel modules that are not signed. To disable Secure Boot, first make sure to find your BitLocker recovery key. Then follow these steps:
- Open the Start menu and open the power menu in the bottom right corner. Then, hold Shift on your keyboard and click Restart. After the PC restarts you will be taken to a blue screen with the following options:
- Continue
- Use a device
- Troubleshoot
- Turn off your PC
- Here, choose Troubleshoot, followed by Advanced options.
- Select UEFI Firmware Settings and then Restart.
- This will take you to your PC's BIOS settings, where you can turn off Secure Boot. Every BIOS is a little different, so you may have to look around. In the HP Omen laptop that we are using, navigate to the BIOS Setup and then from the upper left main menu select Boot Options. There, you can disable Secure Boot by moving the slider to the left. Lastly, click Exit and make sure that the Save Changes and Exit option is selected before choosing Yes.
For this step you'll need to have a USB drive that you can install Ubuntu from. To turn your flash drive into installation media, everything on it will be erased, so make sure you've backed up anything you might need.
- First download the latest version of Ubuntu Desktop LTS (Long-term Support) from the official website.
- Next, you'll need a tool that creates bootable USB drives from ISO files. I am using Rufus for this purpose.
- Run Rufus and insert the flash drive you want to use as installation media. Then, click Select and choose the ISO file you downloaded. All the options will be filled in automatically.
- Click Start, then click OK in the prompt that shows up.
Next, you'll need to create a second partition on your drive for Linux.
- Right-click your Start menu icon (or press Windows key + X on your keyboard) and choose Disk Management. You'll see a list of your drives and partitions.
- Right-click your primary partition (the one labeled as Windows C:) and choose Shrink Volume...
- Specify the amount of space you want to remove from the partition. This will be limited by the files you already have stored on it, and the amount you enter will be the space you have for your Linux installation. In my case, I decided to allocate 500 GB for the Linux partition so I set the amount of space to shring in MB to 512000.
- The space you chose will be deducted from your partition, and it will be listed as unallocated space in the Disk Management window. You can leave it as is and close the window.
Now you're ready to install Linux on your empty partition. If you removed the USB installation media from your PC, insert it again (remove other flash drives), then follow these steps:
- Open the Start menu and then click the power button and — while holding Shift on your keyboard — click Restart.
- Click Use a device, then choose the USB flash drive you have inserted and your PC will boot from it.
- You'll now be in the Ubuntu boot menu. Press Enter to boot into Ubuntu.
- Ubuntu and other Linux operating systems let you try it out by booting from the USB drive without installing it. To install Linux on your empty partition, click Install Ubuntu.
- Follow the setup experience by first choosing your keyboard layout.
- At the Updates and other software section choose to Download updates while isntalling Ubuntu and to Install third-party software for graphics and Wi-Fi hardware and additional media formats, where you will need to set a password for Secure Boot.
- Next, at the Installation type select Something else and click Continue. At the next window select the unallocated space that you have created for install Linux (it should be named as free space). Hit Right Click and select add to create the primary partition for Ubuntu. Set the partition's size (I set it to 526871 MB) and the mount point (in my case I set to `/`) and then click OK. The newly created partition should be listed now. Repeat the process by using the rest of the free space partition (10000 MB) in order to create a swap partition. Finally, click Install Now to continue with installation process.
- Next you will select your timezone and enter your name and computer's name along with a login password.
- Proceed with Ubuntu installation.
- Open the command terminal and search for NVIDIA drivers using the
apt
command:
apt-cache search 'nvidia-driver-' | grep '^nvidia-driver-[[:digit:]]*' | sort -k 3 -t '-'
- Next, use the following two commands as you must apply all pending security updates:
sudo apt update
sudo apt upgrade
- Now, lets install the latest NVIDIA driver (535 as of September 12th, 2023):
sudo apt install nvidia-driver-535 nvidia-dkms-535
- Then, reboot your machine:
sudo reboot
- To verify the NVIDIA drivers installation you can use the NVIDIA System Management Interface (SMI)
nvidia-smi
You can also check the version of the installed drivers:
nvidia-smi --query-gpu=driver_version --format=csv
Conda is an open source package management system and environment management system that runs on Windows, macOS, and Linux. For this guide will be using Miniconda which is a free minimal installer for conda. For installing Miniconda follow the next steps:
- Open a command terminal and execute these four commands to quickly and quietly install the latest 64-bit version of the installer and then clean up afterwards. To install a different version or architecture of Miniconda for Linux, change the name of the
.sh
installer in thewget
command.
mkdir -p ~/miniconda3
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
rm -rf ~/miniconda3/miniconda.sh
- After installing, initialize your newly-installed Miniconda. The following commands initialize for bash and zsh shells:
~/miniconda3/bin/conda init bash
~/miniconda3/bin/conda init zsh
For the purpose of this guideline I will be using the latest version of PyTorch (stable 2.0.1 as of September 12th, 2023)
- First, create and activate a separate conda environmet for PyTorch:
conda create -n torch2 python=3.10
conda activate torch2
- Then, run the following command to install PyTorch with the appropriate version of CUDA:
conda install pytorch torchvision torchaudio pytorch-cuda=11.7 -c pytorch -c nvidia
- To ensure that PyTorch was installed correctly,verify the installation by running the following sample PyTorch code:
python -c "import torch; print(f'{torch.__version__=}'); x = torch.rand(5, 3); print(f'{x=}')"
- Additionally, to check if your GPU driver and CUDA/ROCm is enabled and accessible by PyTorch, run the following commands to return whether or not the GPU driver is enabled:
python -c "import torch; print(f'{torch.cuda.is_available()=}'); x = torch.rand(5, 3); x = x.cuda(); print(f'{x.device}')"
This guide is for the latest stable version of TensorFlow (v2.13.0 as of September 12th, 2023).
- Create a new conda environment named
tf
with the following command:
conda create --name tf python=3.9
You can deactivate and activate it with the following commands.
conda deactivate
conda activate tf
Make sure it is activated for the rest of the installation.
- Then, install CUDA and cuDNN with
conda
andpip
:
conda install -c conda-forge cudatoolkit=11.8.0
pip install nvidia-cudnn-cu11==8.6.0.163
- Next configure the system paths:
mkdir -p $CONDA_PREFIX/etc/conda/activate.d
echo 'CUDNN_PATH=$(dirname $(python -c "import nvidia.cudnn;print(nvidia.cudnn.__file__)"))' >> $CONDA_PREFIX/etc/conda/activate.d/env_vars.sh
echo 'export LD_LIBRARY_PATH=$CUDNN_PATH/lib:$CONDA_PREFIX/lib/:$LD_LIBRARY_PATH' >> $CONDA_PREFIX/etc/conda/activate.d/env_vars.sh
The system paths will be automatically configured when you reactivate this conda environment.
- Install TensorFlow with
pip
:
pip install tensorflow==2.13.*
- Verify the TensorFlow setup:
python3 -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
If a tensor is returned, you've installed TensorFlow successfully.
- Verify the GPU setup:
python3 -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"
If a list of GPU devices is returned, you've installed TensorFlow successfully.
For code development you can use the popular PyCharm IDE
-
Download PyCharm from here.
-
Unpack PyCharm using:
tar -xzvf pycharm*
-
Then, follow the installation instructions found in
pycharm-<version>/Install-Linux-tar.txt
. -
Finally, remove the PyCharm archive:
rm pycharm-*.tar.gz
You may notice, especially in monitors with high resolution, e.g., 3840 x 2160 (4K) or 2560 x 1440 (WQHD), Ubuntu tends to not scale its UI optimally. Thus, fonts and icons may appear very small and not easy to read. Although, Ubunut 22.04.3 allows to scale its UI through the display settings, I prefer to use gnome-tweaks instead. In order to install this tool you will need to go through the following steps:
- Make sure that you have the
universe
repository enabled on your Ubuntu system:
sudo add-apt-repository universe
- Next, execute the following command to install Tweak Tool on your Ubuntu 22.04 system:
sudo apt install gnome-tweaks
-
Finally, run
gnome-tweaks
through your command terminal. -
From the menu on the left select Fonts and then adjust the Scaling Factor accordingly.
bpytop is a resource monitor that shows usage and stats for processor, memory, disks, network and processes.
- Activate the base conda environment:
conda activate
- Install bpytop using
pip
:
pip install bpytop --upgrade
- Run
bpytop
in your command terminal.
nvitop is an interactive NVIDIA-GPU process viewer and beyond, the one-stop solution for GPU process management.
- Activate the base conda environment:
conda activate
- Install nvitop using
pip
:
pip install --upgrade nvitop
- Run
nvitop
in your command terminal.