Guide to Install JupyterLab on Debian 12
Jupyter is a free and open-source web application for interactive computing and data science. Jupyter supports all programming languages and provides multiple software, such as JupyetrLab, which provides a feature-rich and tabbed multi-notebook editing environment, Notebook as a lightweight and simplified notebook authoring, Qtconsole, and many more.
In this guide, we'll take you through the installation of JupyterLab on Debian 12 step-by-step. You will install JupyterLab on Python virtual environment, running JupyterLab as a systemd service, then you will install and set up Nginx as a reverse proxy for JupyterLab.
Prerequisites
Before commencing, confirm that you have the following:
- A Debian 12 server.
- A non-root user with administrator privileges.
Installing Dependencies
Jupyter is an ecosystem of free and open-source Python software for interactive computing across all programming languages. To install Jupyter, you must ensure that Python is installed on your system.
In this section, you will install package dependencies for Jupyter, which includes Python3, Pip package manager, Python venv virtual environment, and Node.js.
Before you begin, update and refresh your Debian package index using the following command.
sudo apt update
Now install dependencies by executing the following apt install command. With this, you will install Python3, Pip package manager, venv virtual environment management, and Node.js.
sudo apt install python3 python3-pip python3-venv nodejs
Type y to confirm and proceed with the installation.
After dependencies are installed, execute the following command to check the version of each dependency, including Python3, Pip, and Node.js
python3 --version
pip3 --version
node --version
The output below shows you that Python 3.11, Pip 23, and Node.js 18.13 are installed.
Installing Jupyter
After installing dependencies, you will next install the Jupyter meta packages using the Python virtual environment on the Debian 12 machine. To achieve that, you must complete the following:
- Creating a Python virtual environment
- Installing Jupyter
- Configuring JupyterLab
Let's start.
Creating Python Virtual Environment
In this section, you will create a new Python virtual environment that will be used for Jupyter installation. With this scenario, you will have an isolated development environment that won't affect your whole system. Also, you can recreate this as time goes on.
Log in to your non-root user using the following command.
su - user
Now create a new directory ~/project and move into it. Then, create a new virtual environment called venv using the following command. After executing the command, the new directory venv will be created.
mkdir -p ~/project; cd ~/project
python3 -m venv venv
Next, run the following command to activate the venv virtual environment. Once activated, your shell prompt will become like "(venv) user@hostname:#...".
source venv/bin/activate
Installing Jupyter
After creating a Python virtual environment. you will install the Jupyter package via Pip. The Jupyter package is a meta package of Jupyter ecosystems, which includes IPython, JupyterLab, Jupyter Server, Jupyter Notebook, qtconsole, and many more.
Execute the pip3 command below to install Jupyter to your Debian system.
pip3 install jupyter
During the installation, below is the output will be shown on your terminal:
After installation is finished, check the location of the Jupyter binary file and version using the following command.
which jupyter
jupyter --version
In the following output, you should see the Jupyter binary file is located within the venv directory. Also, you should see the version of the Jupyter package that is installed on your system.
Configuring JupyterLab
JupyterLab is the next-generation web-based user interface for the Jupyter ecosystem. With JupyterLab, you can work with documents, and activities such as Jupyter Notebook, text editor, and terminal in one window. The JupyterLab offers you an IDE-like experience for managing and developing Jupyter projects.
In this section, you will set up JupyterLab for your Jupyter project. But before that, you must configure the Jupyter Server first to secure your installation.
First, run the following command to generate the Jupyter Server config file and set up the password. Input your password and repeat.
jupyter server --generate-config
jupyter server password
After executing the command, the Jupyter Server configuration will be generated at ~/.jupyter/ directory.
You can verify the content of the Jupyter Server configuration using the following command.
jupyter server --show-config
The similar output below will be shown:
Next, run the following command to generate a new configuration for JupyterLab. The JupyterLab configuration will be generated at the ~/.jupyter/ directory.
jupyter lab --generate-config
After the configuration is generated, verify the JupyterLab configuration using the following command.
jupyter lab --show-config
Below is an example of JupyterLab configuration:
Now you can run JupyterLab installation using the following command. Be sure to change the IP address with your server IP address.
jupyter lab --ip 192.168.10.15
The JupyterLab will be running on your server IP address with default port 8888. The JupyterLab is accessible via URL path /lab.
Open your web browser and visit your server iP address followed by port 8888 and path /lab, such as http://192.168.10.15:8888/lab. Input your Jupyter Server password and click Log in to continue.
If you have the proper password, you should see the JupyterLab user dashboard like the following:
You can now press Ctrl+c twice to terminate the JupyterLab process.
Running JupyterLab as a Systemd Service
In the following step, you will create a new systemd service file that will be used to run JupyterLab. This way, your JupyterLab installation will be running in the background as a systemd service, and you can easily manage JupyterLab via the systemctl utility.
Create a new systemd service file /etc/systemd/system/jupyterlab.service using the following nano editor command.
sudo nano /etc/systemd/system/jupyterlab.service
Insert the following configuration and be sure to change username bob.
[Unit]
Description=JupyterLab Service
[Service]
Type=simple
PIDFile=/run/jupyter.pid
ExecStart=/home/bob/project/venv/bin/jupyter lab --config=/home/bob/.jupyter/jupyter_lab_config.py
User=bob
Group=bob
WorkingDirectory=/home/bob/project
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
When finished, save and close the file.
Now run the following systemctl command to reload the systemd manager and apply the changes.
sudo systemctl daemon-reload
Then, start and enable the jupyterlab service using the following command.
sudo systemctl start jupyterlab
sudo systemctl enable jupyterlab
Lastly, verify the jupyterlab service to ensure that the service is running.
sudo systemctl status jupyterlab
The following output confirms that the jupyterlab service is running.
Configuring Nginx as a Reverse Proxy for Jupyter
In this guide, you will be running JupyterLab with Nginx as a reverse proxy. To achieve that, you must complete the following:
- Allowing Remote Access to JupyterLab
- Installing and Configuring Nginx as a Reverse Proxy
Allowing Remote Access to JupyterLab
By default, the JupyterLab installation is only accessible via a local IP address. To allow remote connection, you must modify the default JupyterLab configuration.
Open the JupyterLab configuration ~/.jupyter/jupyter_lab_config.py using the following nano editor command.
nano ~/.jupyter/jupyter_lab_config.py
Uncomment option c.ServerApp.allow_remote_access and change the value to True. This will make JupyterLab accessible from a remote connection, which includes running JupyterLab behind a reverse proxy.
c.ServerApp.allow_remote_access = True
Save the file and exit the editor when you're done.
Now run the following systemctl command to restart the jupyterlab service and apply the changes.
sudo systemctl restart jupyterlab
Then, verify the jupyterlab service using the following command.
sudo systemctl status jupyterlab
At the bottom output, you should see the generated token for accessing your JupyterLab installation, and be sure to copy it for the next section.
Installing and Configuring Nginx as a Reverse Proxy
After allowing remote access to JupyterLab, you will next install Nginx and configure it as a reverse proxy for your JupyterLab installation.
Install Nginx by executing the apt install command below.
sudo apt install nginx -y
Below is the output during the Nginx installation.
After Nginx is installed, create a new server block configuration /etc/nginx/sites-available/jupyterlab using the following nano editor.
sudo nano /etc/nginx/sites-available/jupyterlab
Insert the following configuration and be sure to change the domain name within the server_name option.
server {
listen 80;
server_name jupyterlab.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 finished.
Now run the following command to activate the server block file /etc/nginx/sites-available/jupyterlab and verify the Nginx configuration.
sudo ln -s /etc/nginx/sites-available/jupyterlab /etc/nginx/sites-enabled/
sudo nginx -t
If you've proper Nginx syntax, you should get the output "syntax is ok - test is successful".
Lastly, run the systemctl command below to restart the nginx service and apply the changes. Then, verify it to ensure that the service is running.
sudo systemctl restart nginx
sudo systemctl status nginx
If Nginx is running, you should get the output active (running).
Access JupyterLab Installation via Local Machine
To access JupyterLab via domain name, you can utilize the /etc/hosts file for Linux clients or C:\Windows\System32\drivers\etc\hosts file for Windows users.
Open the /etc/hosts file on your Linux client using the nano editor.
sudo nano /etc/hosts
Insert the following configuration into the file and be sure to change the IP address and the domain name with your information.
192.168.10.15 jupyterlab.howtoforge.local
Save and exit the file when you're done.
Next, open your web browser and visit the domain name of your JupyterLab installation, such as http://jupyterlab.howtoforge.local. If your installation is successful, you should get the JupyterLab login page.
At the bottom page, input the generated and the new password for your JupyterLab installation. Then click the button Log in and set a new password.
If everything goes well, you should be redirected to the JupyterLab dashboard like the following.
With this, your JupyterLab installation is complete.
Conclusion
By completing this step-by-step guide, you have accomplished the installation of JupyterLab on the Debian 12 server. You've installed JupyterLab using Python virtual environment, running JupyterLab in the background as a systemd service, and configured Nginx as a reverse proxy for JupyterLab. Now you can create and manage your Jupyter Project.