In this tutorial we are going to see how to install Jupyter lab.
More on this tool here: https://jupyterlab.readthedocs.io/en/stable/

Install NodeJS

We are going to install NVM (Node Version Manager) to manage the install NodeJS
version.

1
2
3
sudo apt-get update
sudo apt-get install -y curl
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash

Add the following commands in your ~/.zshrc file:

1
2
3
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion

Once it is done do not forget to reload your terminal with source ~/.zshrc.

Then install the lastest LTS NodeJS version:

1
2
3
4
nvm ls-remote
# Determine the latest LTS. For me it is v10.16.0 when I am writing this tutorial
nvm install v10.16.0
nvm use default v10.16.0

Install python 3

1
2
3
sudo apt-get update
sudo apt-get install python3
sudo apt-get install python3-pip

Install jupyterlab

1
pip3 install jupyterlab

If you are using ohmyzsh (and you should !) edit your ~/.zshrc file and add the line at the end export PATH=$PATH:~/.local/bin/. Then execute source ~/.zshrc.

Verify jupyterlab works

1
jupyter lab --allow-root --ip=0.0.0.0 --no-browser

Install extensions hub

Kill the previously launched server with Ctrl-c

1
2
3
jupyter labextension install @jupyterlab/hub-extension
jupyter lab build
jupyter lab --allow-root --ip=0.0.0.0 --no-browser

Go to “Settings” –> “Enable Extensions manager (Experimental) to enable the extensions manager.
If you click on the extensions icon that appear on the left menu you should see all available extensions to install.

Make Jupyterlab a service

Generate a config file:

1
jupyter-lab --generate-config

Create a working directory:

1
2
mkdir -p /home/$USER/Dev/jupyterlab
export WorkingDirectory=/home/$USER/Dev/jupyterlab

Generate Service file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
cat << EOF | sudo tee /etc/systemd/system/jupyter-lab.service
[Unit]
Description=Jupyter Lab
[Service]
Type=simple
PIDFile=/run/jupyter.pid
ExecStart=/home/$USER/.local/bin/jupyter-lab --config=/home/$USER/.jupyter/jupyter_notebook_config.py
WorkingDirectory=$WorkingDirectory
User=$USER
Group=$USER
Restart=always
RestartSec=10
#KillMode=mixed
[Install]
WantedBy=multi-user.target
EOF

Reload systemctl daemon after creating service entry:

1
sudo systemctl daemon-reload

Enable Jupyter Lab service:

1
sudo systemctl enable jupyter-lab.service

Start the service:

1
sudo systemctl start jupyter-lab.service

Verify jupyterlab service is working and get access token:

1
sudo systemctl status jupyter-lab.service

Custom jupyter conf

It is possible to custom jupyter lab conf with the following commands:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Incoming connection whitelist. tried with IP & CIDR. not sure about ranges. should be comma separated if more than one.
sed -i.back "s/#c.NotebookApp.allow_origin = ''/c.NotebookApp.allow_origin = '10.1.0.0\/24'/" ~/.jupyter/jupyter_notebook_config.py

# Jupyter listening IP. Set to localhost if only planning on using locally.
sed -i "s/#c.NotebookApp.ip = 'localhost'/c.NotebookApp.ip = '$ipAddress'/" ~/.jupyter/jupyter_notebook_config.py

# Whether or not to open browser on jupyter launch. If headless, or server, set to False.
sed -i "s/#c.NotebookApp.open_browser = True/c.NotebookApp.open_browser = False/" ~/.jupyter/jupyter_notebook_config.py

# Listening port. Change if necessary
sed -i "s/#c.NotebookApp.port = 8888/c.NotebookApp.port = 8888/" ~/.jupyter/jupyter_notebook_config.py

# Randomly generated token for access without user/pass
sed -i "s/^#c.NotebookApp.token .*/c.NotebookApp.token = '$token'/" ~/.jupyter/jupyter_notebook_config.py

# Trash Cleanup
sed -i "s/#c.NotebookApp.cookie_secret = b''/#c.NotebookApp.cookie_secret = ''/" ~/.jupyter/jupyter_notebook_config.py
sed -i "s/#c.Session.key = b''/#c.Session.key = ''/" ~/.jupyter/jupyter_notebook_config.py
sed -i "s/#c.NotebookNotary.secret = b''/#c.NotebookNotary.secret = ''/" ~/.jupyter/jupyter_notebook_config.py

Have fun !