JupyterLab is the next-generation web-based user interface for the Jupyter ecosystem, which includes Jupyter Notebook, Editor, iPython, Terminal Shell, and more. It is a free and open source web application that provides an interactive and powerful development environment for developers and scientists. JupyterLab also offers third-party extensions that extend the functionality of the development environment.
With JupyterLab you can work with multiple documents at the same time and enable a new workflow for interactive computing. JupiterLab can handle multiple file formats, including images, JSON, CSV, Markdown, PDF, Vega, Vega-Lite and many more.
In this tutorial, we will show you how to install JupyterLab on the latest Ubuntu 22.04. It also covers some basic configurations of JupyterLab, such as setting up password authentication, running JupyterLab as a systemd service and securing the JupyterLab installation with SSL certificates.
Prerequisites
For this tutorial we need the following prerequisites:
- An Ubuntu 22.04 system - server or desktop version.
- A root user or a non-root user with root sudo privileges.
Installation of Python and Pip
JupyterLab is a Python-based application that can be installed from the PyPi (Python Repository). Now you will install the base package python3-dev with the tool python3-pip to install Python packages from the PyPi repository.
Run the following apt command to update and refresh your current Ubuntu repository.
sudo apt update
After updating the repository to the latest version, run the apt command below again to install the python3-dev and python3-pip packages.
sudo apt install python3-dev python3-pip
Enter Y to confirm the installation and press ENTER to start. The installation will now begin.

Set up a new user
JupyterLab can be installed in different ways, e.g. via the virtual environment, directly on the system or by running JupyterLab under the Unix/Linux user. In this example, you will install JupyterLab under the Unix/Linux user. Therefore, you must now create a new user and set up the sudo rights.
Execute the following command to create a new Unix/Linux user and set up the password for the new user. In this example, you will create a user named"john".
sudo useradd -m -s /bin/bash john passwd john
Next, add the user "john" to the"sudo" group with the following command. This gives the new user "john" the authorization to execute the command"sudo su" and to obtain root rights.
sudo usermod -aG sudo john
Now execute the following command to log in as user "john" and execute the command "sudo su" to check and confirm the root rights.
su - john sudo su
You will be asked for the password for the new user "john", so enter the correct password for your user. If you get the shell prompt like"root@hostname", you have successfully obtained root privileges.

Installing JupyterLab
After you have completed the installation of the Python3-dev base package and created a Unix/Linux user. Now install JupyterLab on your Ubuntu system.
Make sure you are logged in as the new user "john" and then run the following pip command to install the JupyterLab package.
pip install --user jupyterlab
You run the pip command with the"--user" option, which means that the JupyterLab package will be installed under the user's home directory.
The installation will take some time as many Python packages are required for JupyterLab.

After the installation of JupyterLab is complete, run the following command to add the bin path for non-root users"~/.local/bin" to the system"PATH" via the file "~/.bashrc". You must then reload the"~/.bashrc" configuration.
echo "export PATH=$PATH:~/.local/bin/" >> ~/.bashrc source ~/.bashrc
Now check the system PATH with the command below. Make sure that the directory"/home/john/.local/bin" is included in the environment variable "system PATH ".
echo $PATH

Finally, you can run the following command to check the JupyterLab installation.
jupyter --version jupyter lab --help

Configuring the JupyterLab installation
In the previous step, you installed JupyterLab on your Ubuntu system. Now you will configure the JupyterLab installation by setting up password authentication and installing some extensions for JupyterLab.
Before you start configuring JupyterLab, run the following command to create the JupyterLab configuration file. This command creates the default configuration file"~/jupyter/jupyter_lab_config.py", which is the main configuration file of your JupyterLab installation.
jupyter lab --generate-config
Now execute the following command to set up password authentication for JupyterLab. Enter the secure password for your JupyterLab installation and repeat the password for confirmation. Your password authentication will be encrypted and stored in the file"~/.jupyter/jupyter_server_config.json".
jupyter lab password

You can check both the JupyterLab configuration file and the password authentication file with the command below.
cat ~/.jupyter/jupyter_server_config.json less ~/jupyter/jupyter_lab_config.py
Next, you can set up and install the Jupyter Extensions. This is optional, especially if you want to extend some features of your JupyterLab installation. You can also skip this part.
Before you can start installing the JupyterLab extensions, you need to install Node.js on your system. The easiest way to do this is to install Node.js from the official Ubuntu repository.
Run the following apt command to download and install Node.js and npm.
sudo apt install nodejs npm -y
Wait until Node.js and npm are installed on your system and then proceed to the next section.
To install the JupyterLab extensions, run the jupyter command below. In the example below, install the"github" and"toc" extensions officially provided by the Jupyter developers.
jupyter labextension install @jupyterlab/github @jupyterlab/toc
Next, you need to rebuild the JupyterLab after installing an extension. This is a must and will take some time depending on your extension list. You have now completed the configuration of JupyterLab on your Ubuntu system.
jupyter lab build
To check the list of installed extensions on JupyterLab, run the following command jupyter.
jupyter labextension list
Run JupyterLab as a systemd service
Your JupyterLab installation is complete, but not yet running. You can start JupyterLab manually via the command line or, which is the better solution, run JupyterLab as a systemd service, for which you have to create a new systemd service file for JupyterLab.
Before you start configuring JupyterLab's systemd service, run the following command to define your project directory. In this example, all projects are located in the directory"~/Dev/jupyterlab".
mkdir -p ~/Dev/jupyterlab
Now create a new directory for the systemd service file"~/.config/systemd/user/" and create a new JupyterLab service file"jupyterlab.service" using the nano editor.
mkdir -p ~/.config/systemd/user/ nano ~/.config/systemd/user/jupyterlab.service
Paste the following configuration into the file. Make sure that you change the details of the configuration such as port, IP address and the working directory of the project.
[Unit] Description=JupyterLab
[Service]
ExecStart=/home/john/.local/bin/jupyter lab --no-browser --port=8888 --ip=0.0.0.0 --NotebookApp.token= --notebook-dir=/home/john/Dev/jupyterlab
WorkingDirectory=/home/john/Dev/jupyterlab
[Install]
WantedBy=default.target
Save and close the file when you are finished.
Next, run the following command to enable userlingering for the user"john" and reload the systemd manager.
sudo loginctl enable-linger john XDG_RUNTIME_DIR="/run/user/$UID" systemctl --user daemon-reload
Now you can start and activate the JupyterLab service with the command below.
XDG_RUNTIME_DIR="/run/user/$UID" systemctl --user enable jupyterlab.service XDG_RUNTIME_DIR="/run/user/$UID" systemctl --user start jupyterlab.service

Check and verify the JupyterLab service with the following command. You should see that JupyterLab is running as a systemd service on port"8888".
XDG_RUNTIME_DIR="/run/user/$UID" systemctl --user status jupyterlab.service

Secure JupyterLab with SSL
Now you will learn how to secure your JupyterLab installation with SSL certificates. This is the recommended method to secure your JupyterLab, especially if you are running it on the public internet. If you are in a local environment, you can use a self-signed certificate, but if you are on the public internet, you can use the free SSL from Letsencrypt. You must also have a domain name that points to the public IP address of your server.
To generate free SSL from Letsencrypt, you need to install the Letsencrypt client tool like certbot on your system. Run the following apt command to install the certbot tool on your Ubuntu system.
sudo apt install certbot
Type Y to confirm the installation and press ENTER to continue.
After the installation is complete, run the certbot command below to generate SSL Letsencrypt. Make sure you change the email address and domain name. The email address will be used to notify you when the certificate has expired and you need to renew it.
certbot certonly --standalone -m [email protected] --agree-tos --no-eff-email -d domain.com
Now your certificates are available in the directory "/etc/letsencrypt/live/yourdomain.com".
Next, run the following command to change the permission and owner of the"/etc/letsencrypt" directory. This is necessary because your JupyterLab is running as a non-root user.
sudo chmod 750 /etc/letsencrypt sudo chown -R john:john /etc/letsencrypt
Now log in as user"john" and edit the JupyterLab configuration file"~/.jupyter/jupyter_lab_config.py" with the nano editor.
su - john nano ~/.jupyter/jupyter_lab_config.py
Remove the comments in the following lines and change the path of the SSL certificates as indicated below.
c.ServerApp.certfile = '/etc/letsencrypt/live/hwdomain.io/fullchain.pem' c.ServerApp.keyfile = '/etc/letsencrypt/live/hwdomain.io/privkey.pem'
Save and close the file when you are finished.
Finally, you can restart the JupyterLab service to apply the changes in the configuration file. Now JupyterLab is running securely with SSL certificates enabled.
XDG_RUNTIME_DIR="/run/user/$UID" systemctl --user restart jupyterlab.service
Accessing JupyterLab via the web browser
Open your web browser and enter your domain name with the JupyterLab port"8888" (i.e. https://hwdomain. io:8888/) in the address bar. You will then be redirected to the URL path"/lab".
Enter the password for your JupyterLab installation and click on the"Login" button.

If your password is correct, you will see the JupyterLab user dashboard at the bottom. From there, you can create a new Jupyter notebook, access the iPython console and the terminal console, and create a new file with Markdown, Python, and a text file.

Next, click on the"Extension Manager" icon in the left-hand menu and then on"Activate". Now you can install the JupyterLab extensions via the JupyterLab user interface. You can see both official and community extensions in the "DISCOVER" section, and a list of installed extensions can be found in the"INSTALLED" section.

Conclusion
Congratulations! You have now successfully installed JupyterLab on the latest Ubuntu 22.04 system. You have also learned how to configure JupyterLab and how to install JupyterLab extensions. You have also secured the JupyterLab installation with password authentication and SSL certificates.