How to Install Jupyter Notebook on Ubuntu 24.04

Updated on 16 April, 2025
How to Install Jupyter Notebook on Ubuntu 24.04 header image

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.

Prerequisites

Before you begin, you need to:

Install Jupyter Notebook on Ubuntu 24.04

There are multiple ways to install Jupyter Notebook on Ubuntu 24.04. You can install Jupyter Notebook with methods, including the following.

  • Pip.
  • APT package manager.
  • Anaconda.
Install Jupyter Notebook Using Pip

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.

  1. Update APT package index..

    console
    $ sudo apt update
    
  2. Install the virtualenv package:

    console
    $ sudo apt install python3-virtualenv -y
    
  3. Create a new virtual environment named jupyter_env.

    console
    $ virtualenv jupyter_env
    
  4. Activate the virtual environment.

    console
    $ source jupyter_env/bin/activate
    
  5. Install Jupyter Notebook using pip.

    console
    $ pip install jupyter
    
  6. Verify the installed Jupyter Notebook version.

    console
    $ jupyter-notebook --version
    

    You can deactivate the virtual environment anytime by running deactivate.

Access Jupyter Notebook Locally

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.

  1. Generate a Jupyter configuration file.

    console
    $ jupyter notebook --generate-config
    

    The above command will generate a configuration file in ~/.jupyter/jupyter_notebook_config.py.

  2. Open the configuration file.

    console
    $ nano ~/.jupyter/jupyter_notebook_config.py
    
  3. 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:

      python
      c.ServerApp.open_browser = False  # Prevent it from opening a browser on the server
      c.ServerApp.allow_remote_access = True  # Allow external access
      

      Save and exit (Ctrl + X, then Y, then hit Enter).

    • If you installed Jupyter using apt, use:

      python
      c.NotebookApp.open_browser = False  # Prevent it from opening a browser on the server
      c.NotebookApp.allow_remote_access = True
      
  4. Launch Jupyter Notebook.

    console
    $ jupyter notebook
    

    Output:

    .........................................
    [I 2025-04-02 16:25:34.253 ServerApp] Jupyter Server 2.15.0 is running at:
    [I 2025-04-02 16:25:34.253 ServerApp] http://localhost:8888/tree?token=65e7d4f05956703d40b2d01e1e43fa89da8df82e1824e711
    [I 2025-04-02 16:25:34.253 ServerApp]     http://127.0.0.1:8888/tree?token=65e7d4f05956703d40b2d01e1e43fa89da8df82e1824e711
    [I 2025-04-02 16:25:34.253 ServerApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
    [C 2025-04-02 16:25:34.256 ServerApp] 

    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.

    http://127.0.0.1:8888/tree?token=xxxxxxxxxxxxxxxxxxxxxxxxxxxx
  5. 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.

    console
    $ ssh -M -f -N -L 8888:localhost:8888 linuxuser@<SERVER-IP>
    

    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.
  6. Open Jupyter Notebook using the access token you generated earlier.

    http://127.0.0.1:8888/tree?token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  7. Click New and select Python 3 (ipykernel) to start a new notebook.

    create new notebook

  8. Click Select to confirm the Python kernel.

    Choose the Python kernel

  9. Test the Notebook by typing a simple arithmetic operation (like 100 + 20) and press Shift + Enter to run the cell.

    test notebook

    Note

    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.

Create a Jupyter Notebook System Service

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.

  1. Create a new jupyter.service system service file using nano.

    console
    $ sudo nano /etc/systemd/system/jupyter.service
    
  2. 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.

      ini
      [Unit]
      Description=Jupyter notebook (pip Virtual Environment)
      After=network.target
      
      [Service]
      Type=simple
      User=linuxuser
      Group=linuxuser
      WorkingDirectory=/home/linuxuser
      ExecStart=/home/linuxuser/jupyter_env/bin/python -m jupyter notebook
      Restart=always
      RestartSec=10
      
      [Install]
      WantedBy=multi-user.target
      
    • For Anaconda installation.

      ini
      [Unit]
      Description=Jupyter Notebook (Anaconda Installation)
      After=network.target
      
      [Service]
      Type=simple
      User=linuxuser
      Group=linuxuser
      WorkingDirectory=/home/linuxuser
      ExecStart=/bin/bash -c ". /home/linuxuser/anaconda3/etc/profile.d/conda.sh && conda activate jupyter_env && exec jupyter-notebook --config=/home/linuxuser/.jupyter/jupyter_notebook_config.py"
      Restart=always
      RestartSec=10
      
      [Install]
      WantedBy=multi-user.target
      
    • For APT-based installation.

      ini
      [Unit]
      Description=Jupyter Notebook (apt Installation)
      After=network.target
      
      [Service]
      Type=simple
      User=linuxuser
      Group=linuxuser
      WorkingDirectory=/home/linuxuser
      ExecStart=/usr/bin/jupyter-notebook --config=/home/linuxuser/.jupyter/jupyter_notebook_config.py
      Restart=always
      RestartSec=10
      
      [Install]
      WantedBy=multi-user.target
      

      Save and close the file.

  3. Reload systemd to apply the new service changes.

    console
    $ sudo systemctl daemon-reload
    
  4. Enable the service so it runs at boot.

    console
    $ sudo systemctl enable jupyter
    
  5. Start the Jupyter Notebook service.

    console
    $ sudo systemctl start jupyter
    
  6. Check the service status and verify that it's running.

    console
    $ sudo systemctl status jupyter
    

    Your output should be similar to the one below.

    ● jupyter.service - Jupyter notebook (pip Virtual Environment)
        Loaded: loaded (/etc/systemd/system/jupyter.service; enabled; preset: enab>
        Active: active (running) since Thu 2025-04-03 11:32:11 UTC; 8s ago
    Main PID: 9961 (jupyter-notebook)
        Tasks: 1 (limit: 1057)
        Memory: 64.5M (peak: 64.7M)
            CPU: 1.791s
        CGroup: /system.slice/jupyter.service
                └─9961 /home/linuxuser/jupyter_env/bin/python /home/linuxuser/jupyte>

    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.

Conclusion

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.

Comments

No comments yet.