Linux System Administration

Installing Debian Packages in Ubuntu from Terminal #

There are a number of ways to install Debian packages in Ubuntu using the Terminal. I mostly use either of the two package managers - dpkg and gdebi. Among these, dpkg manager is pre-installed in Ubuntu. Below are the minimal commands you would need to install a Debian package with either of the two.

dpkg #

$ cd /download_directory_path    #Change directory to where the .deb file is saved or to be saved
$ wget https://< download.url>       #If you haven't downloaded the package yet
$ sudo dpkg -i file_name.deb     #Run to install the desired Debian package
$ sudo apt-get -f install        #Use this command to install the Debian package if you encounter any error while installing through the above command. You don't need the package name!

gdebi #

First, we need to install gdebi package manager, as it doesn’t come pre-installed in Ubuntu.

$ sudo apt-get install gdebi-core

If we have gdebi installed in the system, then we can use the following commands to install Debian packages.

$ cd /download_directory_path    #Change directory to where the .deb file is saved or to be saved
$ wget https://<download.url>       #If you haven't downloaded the package yet
$ sudo gdebi -n file_name.deb    #Run to install the desired Debian package

Monitor Network Speed in Ubuntu #

If you’re using a Ubuntu version with Unity Desktop, then there is a nice little applet, called netspeed indicator, to monitor real-time network usage. You can view the speed from top menu bar.

The question is - how to install and activate the applet?

First, you need to add the developer PPA in your machine’s package list from the Terminal.

$ sudo add-apt-repository ppa:fixnix/netspeed

Then, update your package lists.

$ sudo apt-get update

Next, install the indicator-netspeed-unity applet.

$ sudo apt-get install indicator-netspeed-unity

Finally, logout and log back in for the applet to appear in your top menu bar.

Updating Nvidia Driver on Ubuntu #

Once, I stumbled upon an error when trying to import tensorflow module in Python. The error message was, "AttributeError: module 'tensorflow.python.training.checkpointable' has no attribute 'CheckpointableBase'". It was an existing installation of TensorFlow in an Anaconda virtual environment. I tried installing the latest version of TensorFlow in a new virtual environment, but it did not work.

$ conda create -n tfgpu
$ source activate tfgpu
$ pip3 install tensorflow-gpu

Instead, it raised a new issue. "Status: CUDA driver version is insufficient for CUDA runtime version". Hence, I checked the CUDA version using nvcc --version command, and decided to install the CUDA toolkit also.

$ conda install cudatoolkit

Installing cudatoolkit solved the new issue, but the old issue arose again. An issue had already been raised on GitHub for this problem, and the solution that worked for me was updating to the latest Nvidia driver.

$ sudo apt update
$ sudo apt upgrade
$ ubuntu-drivers list
# sudo apt install nvidia-VERSION-NUMBER
# For me, the version number was 415
$ sudo apt install nvidia-415 

Install Jupyter Notebook in Anaconda #

If you have installed Jupyter with the following command, and gettting “500 : Internal Server Error” when accessing any IPython notebook then install nbconvert and notebook.

$ conda install jupyter
$ conda install nbconvert notebook

Check TensorFlow and CUDA Version #

For TensorFlow version check:

$ python3
>>> import tensorflow as tf 
>>> tf.VERSION 

For CUDA version check:

$ nvcc --version

Check Available Devices in TensorFlow #

To find available devices in TensorFlow, from Python prompt use -

$ python
>>> import tensorflow as tf
>>> from tensorflow.python.client import device_lib
>>> print(device_lib.list_local_devices())

If you want to find out which device is being used, try -

$ python
>>> import tensorflow as tf
>>> sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))

Source: Stackoverflow

Fresh Reinstall of TensorFlow with CUDA #

I already have an existing TensorFlow installation with CUDA toolkit on Ubuntu 16.04 LTS. For a fresh reinstall of the latest TensorFlow with all required dependencies, I first removed TensorFlow and CUDA toolkit (including NVIDIA driver).

To uninstall TensorFlow, use:

$ source activate tfgpu
$ python3 -m pip uninstall protobuf
$ python3 -m pip uninstall tensorflow-gpu
$ python3 -m pip uninstall tensorflow

The following command will remove everything from NVIDIA, including the GPU driver, CUDA, and cuDNN.

$ sudo apt-get purge nvidia* 

After that, install the latest NVIDIA driver.

$ sudo apt install nvidia-<VERSION-NUMBER>

Decide on the version of TensorFlow you want to install, and the CUDA and cuDNN requirements for that version. Download CUDA 10.0 from NVIDIA website and install it.

$ sudo dpkg -i cuda-repo-ubuntu1604-<VERSION-NUMBER>-1_amd64.deb
$ sudo apt-key add /var/cuda-repo-<VERSION-NUMBER>/7fa2af80.pub
$ sudo apt-get update
$ sudo apt-get install cuda

Now, download cuDNN from NVIDIA developer website. You would need to register an account if you don’t have one.

$ sudo dpkg -i libcudnn7_<VERSION_NUMBER>_amd64.deb 
$ sudo dpkg -i libcudnn7-dev_<VERSION-NUMBER>_amd64.deb 
$ sudo dpkg -i libcudnn7-doc_<VERSION_NUMBER>_amd64.deb 

After installing CUDA and cuDNN, you would need to set the environment variable. Otherwise, you might encounter an error like this when importing TensorFlow in Python - "ImportError: libcublas.so.10.0: cannot open shared object file: No such file or directory".

You can also go for the easier option of installing through Anaconda in this, instead of the above two.

$ conda install cuda
$ conda install cudatoolkit

Reboot your system and check if the installation was correct.

$ nvidia-smi

Now, install TensorFlow using pip.

$ python3 -m pip install tensorflow-gpu

Check if the TensorFlow is working correctly.

$ source activate tfgpu
$ python3
>>> import tensorflow as tf
>>> tf.VERSION #or tf.__version__
>>> sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
© 2024 Manoj Pravakar