Quick Set-up of “Miniconda” and “Jupyter” to access remotely on Ubuntu 20.04 server.

Vinura Dhananjaya
4 min readJun 17, 2021

--

Photo by Jan Kopřiva on Unsplash

Sometimes you will have to access GPU resources on remote servers, outside your personal workstation/PC and it might be all yourself who has to setup the things. Here, in this short article I will be sharing a basic set of commands that I made use of, to setup miniconda, tensorflow-gpu and access Jupyter server on a remote server running Ubuntu 20.04 (There can be other ways too). I am assuming that there’s no GUI on this Ubuntu installation (only CMD), it can access public internet to download required packages, libraries etc. and it has CUDA installed on it.

Installing Miniconda

“Miniconda” is the lite version of “Anaconda”; which is a software distribution that makes data science, ML, deep learning related work much simpler such that you will have to worry less about package management, installation & deployment kind of stuff. You will have to download a shell script to install the Miniconda software on Ubuntu.

wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh

This will download the shell script required to download the latest version of Miniconda3. You then need to make this shell script executable and run it. Make sure you are in the directory where the shell script was downloaded to. Remember, with these commands, it might throw an error if you already have a folder named “miniconda3” in the installation directory, which the shell script creates itself.

chmod +x Miniconda3-latest-Linux-x86_64.sh./Miniconda3-latest-Linux-x86_64.sh

This will install Miniconda on the machine. When it asks to automatically initialize conda, during the setup, it’s recommended to do so as it will automatically configure the PATH variables needed. (https://docs.anaconda.com/anaconda/user-guide/faq/ — You can do initialization after the installation as well which is manually done.)

Installing Tensorflow, Jupyter etc.

You can install Jupyter as below,

conda install -y jupyter

where -y flag is for “Do not ask for confirmation”. (conda install — conda 4.10.1.post31+7dbd2729e documentation)

It’s better to have virtual environments in conda (or Miniconda) rather than installing all packages to one shared environment, so you will have isolated environments which are easier to handle and maintain. (By default, conda activates “base” environment (the default environment) when you open a terminal session to the server, if you allowed to do so in the installation — which I assume okay here. You can also change that setting if needed). So you may create & activate a virtual environment by executing,

conda create --name tfenv python=3.8conda activate tfenv

The “tfenv” virtual environment will be created and activated. You will see “(tfenv)” replacing “(base)” on the shell. A suitable Python installation could be selected. (As of now, Python 3.8 needs Tensorflow 2.2 or later). One should note that based on the CUDA version that has been installed, the available/required Tensorflow version changes and so does the Python version needed. (eg:- As of today, Tensorflow 2.5 needs CUDA version 11.2 and if one uses Python 3.9, Tensorflow 2.5 or higher is needed — kind of inter-dependent)

Now, below commands can be given to bind the “tfenv” to Jupyter installation we have installed and install tensorflow-gpu version. Nice thing is that conda handles the dependencies so we do not have to worry about much.

conda install nb_condapython -m ipykernel install --user --name tfenv --display-name “tfenv-Python3.8”conda install -c anaconda tensorflow-gpu

You can check whether it has been installed and it’sversion, being in the activated “tfenv” on the terminal, by executing below commands,

pythonimport tensorflow as tftf.__version__quit()

Connecting to notebooks remotely

Typically, Jupyter notebooks need a web browser to run and here our server doesn’t have a browser installed and it supports CLI only. Being in the above activated virtual environment (“tfenv”),

jupyter notebook --no-browser --ip=0.0.0.0 --port=<remoteport>

the port flag & value (<remoteport>) is optional which might be needed if you manually change the default port of Jupyter;8888 to a preferred one. The “ — no-browser” flag will run Jupyter on the server without attaching to a browser (which is already not present). Afterwards, you can access this running Jupyter server on your browser. You can take a separate terminal and,

ssh -N -f -L localhost:<localport>:localhost:<remoteport> username@remoteserver

The -N flag is used in port forwarding, -f makes ssh command to go to background and -L for binding the remote and our local port. (ssh man page (linuxcommand.org)). Finally, you can open a browser on your local machine, and access the remote Jupyter server via ‘localhost:<localport>’ and start working on the remote machine. That’s it!

This is a nice article about overall process of setting up deep learning workstation, that I referred to. (Setting up your PC/Workstation for Deep Learning: Tensorflow and PyTorch — Windows | by Abhinand | Towards Data Science)

Update (2023):

conda install nb_conda

Setting up Jupyter-related configurations with the above command may throw an error. In that case, replace it with the below commands. The rest should be fine.

conda install -c conda-forge ipykernel
conda install nb_conda

--

--

No responses yet