JupyterLab is a powerful and versatile web application that enables interactive computing and data science. It offers a feature-rich and tabbed multi-notebook editing environment, making it an essential tool for developers and data scientists. In this comprehensive guide, we will walk you through the step-by-step process of installing JupyterLab on Debian 12. By the end of this guide, you will have a fully functional JupyterLab installation, running on a Python virtual environment and configured as a systemd service, with Nginx acting as a reverse proxy.
Table of Contents
- Prerequisites
- Installing Dependencies
- Creating a Python Virtual Environment
- Installing Jupyter
- Configuring JupyterLab
- Running JupyterLab as a Systemd Service
- Configuring Nginx as a Reverse Proxy for Jupyter
- Allowing Remote Access to JupyterLab
- Installing and Configuring Nginx as a Reverse Proxy
- Accessing JupyterLab Installation via Local Machine
- Conclusion
1. Prerequisites
Before diving into the installation process, let’s ensure that you have the necessary prerequisites in place:
- A Debian 12 server
- A non-root user with administrator privileges
2. Installing Dependencies
To install JupyterLab, we need to make sure that Python and other dependencies are installed on your system. Let’s start by updating and refreshing the Debian package index:
sudo apt update
Now, install the required dependencies by executing the following command:
sudo apt install python3 python3-pip python3-venv nodejs
3. Creating a Python Virtual Environment
Creating a Python virtual environment allows us to have an isolated development environment for JupyterLab. It ensures that the installation won’t interfere with the rest of your system. Follow these steps to create a new virtual environment:
su - user mkdir -p ~/project && cd ~/project python3 -m venv venv source venv/bin/activate
4. Installing Jupyter
With the virtual environment set up, we can now install Jupyter using the following command:
pip3 install jupyter
5. Configuring JupyterLab
Before we can start using JupyterLab, we need to configure it. Let’s begin by setting up the Jupyter Server to secure your installation:
jupyter server --generate-config jupyter server password
The first command generates the Jupyter Server configuration file in the ~/.jupyter/
directory. The second command allows you to set a password for accessing your JupyterLab installation.
Next, generate a new configuration file for JupyterLab itself:
jupyter lab --generate-config
You can now run JupyterLab using the following command:
jupyter lab --ip 192.168.10.15
Replace 192.168.10.15
with your server’s IP address. JupyterLab will be accessible via the URL path /lab
.
6. Running JupyterLab as a Systemd Service
To ensure that JupyterLab runs continuously as a background service, we can create a systemd service file. Follow these steps to set it up:
sudo nano /etc/systemd/system/jupyterlab.service
Insert the following configuration into the file:
[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
Save and close the file. Then reload the systemd manager and start the service:
sudo systemctl daemon-reload
sudo systemctl start jupyterlab
To ensure that the service is running, you can check its status:
sudo systemctl status jupyterlab
7. Configuring Nginx as a Reverse Proxy for Jupyter
To access JupyterLab securely over the internet, we can set up Nginx as a reverse proxy. This allows us to use a domain name and HTTPS encryption. Let’s start by allowing remote access to JupyterLab:
nano ~/.jupyter/jupyter_lab_config.py
Uncomment the line c.ServerApp.allow_remote_access
and set the value to True
. Save the file and restart the JupyterLab service:
sudo systemctl restart jupyterlab
Next, install Nginx:
sudo apt install nginx -y
Create a new server block configuration file for JupyterLab:
sudo nano /etc/nginx/sites-available/jupyterlab
Insert the following configuration, replacing jupyterlab.test.io
with your desired domain name:
server { listen 80; server_name jupyterlab.test.io; access_log /var/log/nginx/test.io.access.log; error_log /var/log/nginx/test.io.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 close the file. Then, activate the server block and verify the Nginx configuration:
sudo ln -s /etc/nginx/sites-available/jupyterlab /etc/nginx/sites-enabled/ sudo nginx -t
Finally, restart Nginx and check its status:
sudo systemctl restart nginx sudo systemctl status nginx
8. Allowing Remote Access to JupyterLab
To allow remote access to JupyterLab, we need to modify the JupyterLab configuration. Open the JupyterLab configuration file:
nano ~/.jupyter/jupyter_lab_config.py
Uncomment the line c.ServerApp.allow_remote_access
and set the value to True
. Save the file and restart the JupyterLab service:
sudo systemctl restart jupyterlab
9. Installing and Configuring Nginx as a Reverse Proxy
To enable secure access to JupyterLab through a domain name, we’ll install and configure Nginx as a reverse proxy. Begin by installing Nginx:
sudo apt install nginx -y
Create a new server block configuration file for JupyterLab:
sudo nano /etc/nginx/sites-available/jupyterlab
Insert the following configuration, replacing jupyterlab.test.io
with your desired domain name:
server { listen 80; server_name jupyterlab.testn.io; access_log /var/log/nginx/test.io.access.log; error_log /var/log/nginx/test.io.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 close the file. Then, activate the server block and verify the Nginx configuration:
sudo ln -s /etc/nginx/sites-available/jupyterlab /etc/nginx/sites-enabled/ sudo nginx -t
Finally, restart Nginx and check its status:
sudo systemctl restart nginx sudo systemctl status nginx
10. Accessing JupyterLab Installation via Local Machine
To access JupyterLab from your local machine, you need to modify the hosts file. Open the hosts file:
sudo nano /etc/hosts
Insert the following configuration, replacing 192.168.10.15
with your server’s IP address and jupyterlab.test.io
with your desired domain name:
192.168.10.15 jupyterlab.hwdomain.io
Save and close the file. Now, open your web browser and visit the domain name you set up for JupyterLab, such as http://jupyterlab.test.io
. You should see the JupyterLab login page. Enter the password you set up earlier, and you’ll be redirected to the JupyterLab dashboard.
11. Conclusion
Congratulations! You have successfully installed JupyterLab on Debian 12 and configured it as a systemd service, with Nginx acting as a reverse proxy. You can now leverage the power of JupyterLab for interactive computing and data science. Enjoy exploring the possibilities it offers for your projects.
If you’re looking for reliable and scalable cloud hosting solutions, consider Shape.host’s SSD Linux VPS services. Our expertise in cloud hosting can provide you with a secure and efficient environment to run your JupyterLab installations and other applications.