
Jupyter Notebook is a popular open-source web interface that allows used to create and share documents containing live code, visualizations, and narrative text. It's widely used in data science, machine learning, and academic research for its ease of use and interactive capabilities.
This article explains how to install Jupyter Notebook on Ubuntu 24.04. You will configure the Jupyter notebook for remote access and set it up to run automatically as a systemd service on boot.
Before you begin, you need to:
sudo privileges.There are multiple ways to install Jupyter Notebook on Ubuntu 24.04. You can install Jupyter Notebook with methods, including the following.
This method uses Python’s pip package manager to install Jupyter Notebook in an isolated virtual environment. It allows you to manage dependencies without interfering with system packages. Follow the steps below to install Jupyter Notebook using Pip.
Update APT package index..
Install the virtualenv package:
Create a new virtual environment named jupyter_env.
Activate the virtual environment.
Install Jupyter Notebook using pip.
Verify the installed Jupyter Notebook version.
You can deactivate the virtual environment anytime by running deactivate.
To access Jupyter Notebook from your local machine, first configure the application, then establish an SSH tunnel to securely forward the port. Follow the steps below to configure Jupyter Notebook and set up port forwarding to access the application locally.
Generate a Jupyter configuration file.
The above command generates a configuration file ~/.jupyter/jupyter_notebook_config.py.
Open the configuration file.
Add the following configuration below the line c = get_config() #noqa to the jupyter_notebook_config.pyfile depending on your installation method.
If you installed Jupyter using pip or Anaconda, use:
Save and exit (Ctrl + X, then Y, then hit Enter).
If you installed Jupyter using apt, use:
Launch Jupyter Notebook.
Output:
Copy the full tokenized URL and paste it into your local browser to access the Jupyter interface. The token provides secure access to the Notebook server without a password.
Run the following command to create an SSH tunnel on your local workstation to forward traffic from the remote server port 8888 to your localhost port 8888.
Replace linuxuser with your sudo username and <SERVER-IP> with your server's IP address. Within the above command.
-M: Enables SSH connection monitoring.-f: Runs the command in the background after authentication.-N: Prevents remote command execution.-L 8888:localhost:8888: Binds local port 8888 to the remote server’s port 8888.Open Jupyter Notebook using the access token you generated earlier.
Click New and select Python 3 (ipykernel) to start a new notebook.
Click Select to confirm the Python kernel.
Test the Notebook by typing a simple arithmetic operation (like 100 + 20) and press Shift + Enter to run the cell.
This article uses SSH tunneling, which doesn’t require opening ports. However, if you plan to expose Jupyter directly without tunneling, run the jupyter notebook --ip=0.0.0.0 command open and manually allow the port using the sudo ufw allow 8888/tcp command.
You can configure Jupyter Notebook to launch automatically on system startup using a systemd service. The setup differs slightly based on how you installed Jupyter. Follow the steps below to set up a new Jupyter Notebook system service to automatically start it at boot.
Create a new jupyter.service system service file using nano.
Add the appropriate configurations to the file depending on your installation method. Replace linuxuser with your actual sudo user and adjust any paths as needed.
For pip (virtual environment) installation.
For Anaconda installation.
For APT-based installation.
Save and close the file.
Reload systemd to apply the new service changes.
Enable the service so it runs at boot.
Start the Jupyter Notebook service.
Check the service status and verify that it's running.
Your output should be similar to the one below.
If you run Jupyter as root, it can create files that are only accessible by root. If the systemd service fails to start or throws permission errors, check the ownership of these files and change them back to your non-root sudo user.
You have installed Jupyter Notebook on Ubuntu 24.04 using three different methods: pip, APT, and Anaconda. Each method serves a different use case, so you can choose the one that best fits your workflow. You also configured Jupyter Notebook for local browser access using SSH port forwarding and set it up to run on boot with a systemd service. Use pip if you want a lightweight, isolated environment, APT for system-managed installations, and Anaconda if you're working with data science tools out of the box.
0 Comments
Be the first to comment and share your perspective with the community.