A Step-by-Step Guide to Installing JupyterLab on Ubuntu 24.04

JupyterLab is an open-source web-based interactive development environment that extends the classic Jupyter Notebook experience, providing a more flexible and powerful interface for data science and scientific computing tasks. It supports various programming languages, with a strong focus on Python, and offers features like code editing, data visualization, and interactive output in a single, integrated workspace. JupyterLab allows users to create and manage notebooks, text editors, terminals, and other custom components in a tabbed layout, enhancing productivity and collaboration. On Ubuntu, it can be easily installed via package managers like apt or through Python’s package installer pip, making it an accessible tool for developers and researchers using this popular Linux distribution.

In this guide, you’ll learn how to install Jupyter on Ubuntu 24.04. You’ll install and secure Jupyter with password authentication. Then you’ll install Nginx and configure it as a reverse proxy.

Prerequisites

Before you start, ensure you have the following requirements:

  • An Ubuntu 24.04 system.
  • A non-root user with administrator privileges.
  • A domain name pointed to the server’s IP address (public or private).

Installing Dependencies

In this section, you’ll install dependencies for Jupyter, which include Python, pip, venv, and Node.js. These packages are available by default in the Ubuntu repository, and you’ll install them through the APT package manager.

To start, run the following command to update your Ubuntu package index:

sudo apt update

Now, install Python3 and Node.js through the Ubuntu repository by executing the command below. Confirm the installation by entering Y when prompted:

sudo apt install python3-dev python3-pip python3-venv nodejs npm

install dependencies

After the installation completes, verify the Python, Node.js, and pip versions with the following commands:

python3 -v
pip3 -v
node -v

You should see Python 3.12, Node.js 18, and pip 24 installed, as shown below:

check version

Installing Jupyter

After installing dependencies, you’ll install Jupyter through pip in a Python virtual environment. You’ll run Jupyter as a non-root user, so ensure this user is created. Log in as this user using the command below. The following example uses the user alice:

su - alice

Create a new directory ~/Dev and navigate into it. Then, create a new Python venv virtual environment:

mkdir -p ~/Dev; cd ~/Dev
python3 -v venv venv

Activate the venv virtual environment with the following command. Once activated, your shell should look like (venv) user@hostname:

source venv/bin/activate

Next, install Jupyter using the pip3 command below:

pip3 install jupyter

installing jupyter

Once the process finishes, verify the Jupyter version with this command:

jupyter --version

You will see the version of each Jupyter component, including jupyterlab, jupyter_server, jupyter_client, jupyter_core, and iPython.

Configuring Jupyter

In this section, you’ll configure two main components of Jupyter: jupyter_server and jupyterlab. You’ll generate configurations and set up password authentication for both, then run Jupyter from the command line.

First, use the jupyter command below to generate the jupyter_server configuration and set a password. Enter your chosen password when prompted and confirm it.

jupyter server --generate-config
jupyter server password

The configurations for jupyter_server are stored in ~/.jupyter/jupyter_server_config.py, and the password file is stored in ~/.jupyter/jupyter_server_config.json as shown:

generate server configuration and password

Check the jupyter_server configuration using this command:

jupyter server --show-config

You should see output similar to the following:

show server configuration

Now, create and check the jupyterlab configuration using these commands:

jupyter lab --generate-config
jupyter lab --show-config

The default URL path for jupyterlab is /lab, as shown in the following output:

generate jupyterlab configuration

Run the command below to start jupyterlab from the command line. jupyterlab should run on port 8888 with the URL path of lab:

jupyter lab --ip 0.0.0.0

running jupyter from command line

Visit http://server-ip:8888/lab to access your jupyterlab installation. The following Jupyter dashboard should appear:

test jupyter

Press Ctrl+c and type yes to terminate the jupyterlab process.

Running JupyterLab as a Service

To run Jupyter in the background as a service, create a new systemd service file for Jupyter.

Create a new systemd service file at /etc/systemd/system/jupyterlab.service using the nano editor:

sudo nano /etc/systemd/system/jupyterlab.service

Input the following configuration, ensuring you replace the user alice with your username:

[Unit]
Description=JupyterLab Service

[Service]
Type=simple
PIDFile=/run/jupyter.pid
ExecStart=/home/alice/Dev/venv/bin/jupyter lab --config=/home/alice/.jupyter/jupyter_lab_config.py
User=alice
Group=alice
WorkingDirectory=/home/alice/Dev
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target

Save the file and exit the editor when done. Now run the following command to reload the systemd manager and activate your new service file:

sudo systemctl daemon-reload

Start and enable the jupyterlab service with these commands:

sudo systemctl start jupyterlab
sudo systemctl enable jupyterlab

jupyter systemd

Finally, check the jupyterlab service status to ensure it is running and enabled on your system:

sudo systemctl status jupyterlab

check jupyter status

Allowing Remote Access to Jupyter

Before setting up Nginx as a reverse proxy, you need to allow remote access on the jupyterlab. Modify the file ~/.jupyter/jupyter_lab_config.py to enable remote access.

First, open the jupyterlab configuration file using nano:

nano ~/.jupyter/jupyter_lab_config.py

Uncomment the c.ServerApp.allow_remote_access option and set it to True to enable remote access for jupyterlab.

c.ServerApp.allow_remote_access = True

Save and exit the file when finished.

Restart the jupyterlab service to apply your changes. When remote access is enabled in Jupyter, a new token for setting up a password will be generated:

sudo systemctl restart jupyterlab

Note the generated token at the bottom of the message for future use in Jupyter.

jupyter token

Setting up Nginx as a Reverse Proxy

In this section, you’ll install and configure Nginx as a reverse proxy for your Jupyter installation. Ensure you have a domain name, whether public or private.

Install the Nginx web server using the command below. When prompted, enter Y to proceed with the installation:

sudo apt install nginx

install nginx

Once the installation is complete, create a new Nginx server block configuration file at /etc/nginx/sites-available/jupyterlab using the nano editor:

sudo nano /etc/nginx/sites-available/jupyterlab

Add the following configuration, ensuring you update the domain name in the server_name option:

server {
    listen 80;
    server_name lab.howtoforge.local;

    access_log /var/log/nginx/howtoforge.local.access.log;
    error_log /var/log/nginx/howtoforge.local.error.log;

    location / {
        proxy_pass http://127.0.0.1:8888;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $http_host;
        proxy_http_version 1.1;
        proxy_redirect off;
        proxy_buffering off;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_read_timeout 86400;
    }
}

Save and exit the file when done.

Activate the jupyterlab server block and verify your Nginx syntax using these commands. If the configuration is correct, you will see syntax is ok ... test is successful:

sudo ln -s /etc/nginx/sites-available/jupyterlab /etc/nginx/sites-enabled/
sudo nginx -t

Restart Nginx to apply your new jupyterlab server block configuration. After running the command below, your Jupyter should be running under the Nginx reverse proxy:

sudo systemctl restart nginx

setup nginx reverse proxy

Accessing Jupyter

If you’re using Linux or macOS, edit the /etc/hosts file. For Windows users, edit the C:\System32\drivers\etc\hosts file as an administrator.

Add your server’s IP address and the domain name to Jupyter like the following:

192.168.5.65 lab.howtoforge.local

Save and exit the file.

Open your web browser and visit your Jupyter domain name, such as http://lab.howtoforge.local/. If your configuration is successful, you will see the Jupyter login page.

Scroll down to the bottom, paste the token for your Jupyter installation, input the new password for Jupyter, and click Log in and set new password.

login token and change password

If successful, you’ll see the Jupyter dashboard, as shown below, and your password for Jupyter will be updated:

dashboard

Conclusion

Congratulations! You’ve successfully installed Jupyter on Ubuntu 24.04. Your Jupyter instance is now running with Nginx set up as a reverse proxy and secured with password authentication. If you’re hosting Jupyter on a public server or VPS, it’s crucial to implement HTTPS for Nginx. You can achieve this using Certbot and Let’s Encrypt.

FAQ

  • What is JupyterLab?
    JupyterLab is an open-source web-based interactive development environment that extends Jupyter Notebook’s capabilities, focusing on data science and scientific computing tasks.
  • Can I use JupyterLab with languages other than Python?
    Yes, JupyterLab supports various programming languages, although it strongly focuses on Python.
  • Why set up Nginx as a reverse proxy for JupyterLab?
    Nginx improves JupyterLab security and scalability by handling client requests and forwards them to JupyterLab.
  • Should I implement HTTPS on my JupyterLab server?
    Yes, for secure communication, especially when accessing JupyterLab over the internet, you should implement HTTPS using tools like Certbot with Let’s Encrypt.
  • Where is the JupyterLab configuration file stored?
    Configuration files are stored in the user’s home directory under ~/.jupyter.