Install JupyterLab on Ubuntu 24.04

Running JupyterLab as a headless server on Ubuntu is perfect for data science, education, or research. In this guide, we’ll set up JupyterLab with a dedicated user, password authentication, remote access, and persistent service using systemd.


  1. Create a Dedicated User
sudo adduser --disabled-password --gecos "" jupyter

This creates a jupyter user that we’ll use to isolate the JupyterLab environment.


  1. Install Required Packages
sudo apt update && sudo apt install -y \
  python3 \
  python3-pip \
  python3-venv

  1. Install JupyterLab in a Virtual Environment

Switch to the new user:

sudo su - jupyter

Create and activate a virtual environment:

python3 -m venv ~/jupyterlab-venv
source ~/jupyterlab-venv/bin/activate

Install JupyterLab:

pip install --upgrade pip
pip install jupyterlab

  1. Set a Password and Configure Remote Access

Generate the default config:

jupyter lab --generate-config

Set the password:

jupyter lab password

Copy the generated password hash from:

cat ~/.jupyter/jupyter_server_config.json

It looks like:

{
  "IdentityProvider": {
    "hashed_password": "argon2:$argon2id$v=19$m=10240,t=10,p=...."
  }
}

Now open the main config file:

vi ~/.jupyter/jupyter_lab_config.py

Add these lines, replacing the hash with yours:

c.PasswordIdentityProvider.hashed_password = 'argon2:$argon2id$v=19$m=10240,t=10,p=....'
c.ServerApp.ip = '0.0.0.0'
c.ServerApp.port = 8888
c.ServerApp.open_browser = False
c.ServerApp.allow_remote_access = True

Exit back to your main user:

exit

  1. Create a systemd Service

Create the service unit:

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

Paste the following:

[Unit]
Description=JupyterLab Server
After=network.target

[Service]
Type=simple
User=jupyter
WorkingDirectory=/home/jupyter
ExecStart=/home/jupyter/jupyterlab-venv/bin/jupyter lab --config=/home/jupyter/.jupyter/jupyter_lab_config.py
Restart=on-failure

[Install]
WantedBy=multi-user.target

  1. Start and Enable the Service
sudo systemctl daemon-reload
sudo systemctl enable --now jupyterlab

Check the status:

systemctl status jupyterlab

Final Result

Visit:

http://<your-server-ip>:8888

login with your password and you’re in!

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top