Jupyter Notebook lets you keep code, results, charts and explanatory notes together. That makes it useful for experimenting with Python and documenting an analysis as you work. This guide covers installing Jupyter Notebook on Ubuntu 22.04.
Prerequisites
Before we embark on the installation journey, make sure you have the following:
Let’s dive right in by updating and upgrading your system’s software packages:
apt update -y
apt upgrade –y
With your packages up to date, we’re ready to proceed.
Install Python
Jupyter Notebook relies on Python, so let’s ensure it’s installed along with other necessary dependencies:
apt-get install python3 python3-pip -y
Verify your Python installation
python3 –version
Ensure your PIP (Python Package Installer) is up to date
pip3 install –upgrade pip
Install Jupyter Notebook
Let’s create a directory to house your notebook and set up a Python virtual environment:
mkdir -p /opt/project
cd /opt/project
virtualenv notebookenv
source notebookenv/bin/activate
Now, let’s install Jupyter Notebook
pip install jupyter
With Jupyter Notebook installed, let’s launch it:
jupyter notebook –allow-root
It is recommended to secure the Jupyter Notebook with password. First, generate a Jupyter Notebook configuration file with the following command:
jupyter notebook –generate-config
You should see the following output
Writing default config to: /root/.jupyter/jupyter_notebook_config.py
To enhance security, let’s set a password for Jupyter Notebook:
jupyter notebook password
Next, deactivate from the Python virtual environment with the following command:
deactivate
Create a Systemd Service File for Jupyter Notebook
To ensure Jupyter Notebook runs seamlessly, let’s create a systemd service file:
vi /etc/systemd/system/jupyter.service
Populate the file with the following content
[Unit]
Description=Jupyter Notebook
[Service]
Type=simple
PIDFile=/run/jupyter.pid
ExecStart=/opt/project/notebookenv/bin/jupyter-notebook –config=/root/.jupyter/jupyter_notebook_config.py –allow-root
User=root
Group=root
WorkingDirectory=/opt/project/notebookenv
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target

After saving and closing the file, reload the systemd daemon
systemctl daemon-reload
Start and enable the Jupyter Notebook service
systemctl start jupyter
systemctl enable jupyter
To verify the status of the Jupyter Notebook, run the following command:
systemctl status jupyter
Configure Nginx as a Reverse Proxy for Jupyter Notebook
To access Jupyter Notebook via port 80, let’s configure Nginx as a reverse proxy:
apt-get install nginx -y
vi /etc/nginx/conf.d/jupyter.conf
Add the following configuration
upstream notebook {
server 127.0.0.1:8888;
}
server {
listen 80;
server_name jupyter.example.com;
access_log /var/log/nginx/example.com.access.log;
error_log /var/log/nginx/example.com.error.log;
location / {
proxy_pass http://localhost: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;
}
}

After saving and closing the file, verify the Nginx configuration
nginx -t
If the test is successful, restart Nginx
systemctl restart nginx
systemctl status nginx
Next, edit the Jupyter Notebook configuration file and enable remote access:
vi /root/.jupyter/jupyter_notebook_config.py
Edit the following line:
c.ServerApp.allow_remote_access = True
Save and close the file, then restart the Jupyter Notebook service to apply the changes:
systemctl restart jupyter
Once you are done, you can proceed to the next step.
Access Jupyter Notebook
Now, open your web browser and access the Jupyter Notebook using the URL http://jupyter.example.com. You will be asked to provide your Jupyter Notebook password on the following screen:

Provide your password and click on the Login button. You should see the Jupyter Notebook dashboard on the following screen:

Conclusion
Congratulations! You’ve successfully installed Jupyter Notebook on Ubuntu 22.04 and configured it with Nginx as a reverse proxy. Armed with this powerful tool, you’re ready to embark on your data exploration and analysis journey. Should you have any questions or encounter hurdles along the way, don’t hesitate to reach out. Happy coding!
We use essential cookies to run this website and optional cookies for analytics and advertising. Choose Accept All, Reject, or Preferences to manage optional cookies. You can change your choice at any time.
Manage your cookie preferences below:
Essential cookies enable basic functions and are necessary for the proper function of the website.
These cookies are needed for adding comments on this website.
Google Tag Manager simplifies the management of marketing tags on your website without code changes.
Statistics cookies collect information anonymously. This information helps us understand how visitors use our website.
Google Analytics is a powerful tool that tracks and analyzes website traffic for informed marketing decisions.
Service URL: policies.google.com (opens in a new window)
You can find more information in our Privacy Policy and Privacy Policy.

Leave a Reply