Ubuntu

How to Install Jupyter Hub on Ubuntu 22.04 LTS

Jupyter Hub is a web-based interactive development environment that allows all the users of your computer to use Jupyter Notebooks. Jupyter Hub allows sharing of the resources of a computer to the students/researchers of a lab for programming, artificial intelligence, machine learning, deep learning, data science, and other projects. It’s a great tool.

In this article, we will show you how to install Jupyter Hub on Ubuntu 22.04 LTS and how to access it from a web browser. We will also show you how to create/upload your first Jupyter Notebook on Jupyter Lab.

Topic of Contents:

  1. Updating the APT Package Database Cache
  2. Installing Jupyter Hub on Ubuntu 22.04 LTS
  3. Configuring the External Access for Jupyter Hub on Ubuntu 22.04 LTS
  4. Restarting the Jupyter Hub Service on Ubuntu 22.04 LTS
  5. Accessing Jupyter Hub from the Web Browser
  6. Creating/Uploading a Jupyter Notebook from Jupyter Hub Web Interface
  7. Conclusion

Updating the APT Package Database Cache

First, update the APT package database cache with the following command:

$ sudo apt update

The APT package database cache should be updated.

A screenshot of a computer Description automatically generated

Installing Jupyter Hub on Ubuntu 22.04 LTS

To install Jupyter Hub along with Python 3 PIP (so that the Jupyter Hub users can install the Python packages as they need from Jupyter Notebooks) on Ubuntu 22.04 LTS, run the following command:

$ sudo apt install python3-pip jupyterhub

To confirm the installation, press “Y” and then press <Enter>.

Jupyter Hub, Python 3 PIP, and the required dependency packages are being downloaded from the internet. It takes a while to complete.

A screenshot of a computer screen Description automatically generated

Jupyter Hub, Python 3 PIP, and the required dependency packages are being installed. It takes a while to complete.

A screenshot of a computer program Description automatically generated

Jupyter Hub and Python 3 PIP should be installed at this point.

A screenshot of a computer program Description automatically generated

Configuring the External Access for Jupyter Hub on Ubuntu 22.04 LTS

By default, the external access is disabled for Jupyter Hub. So, you won’t be able to access Jupyter Hub from other computers on the network. To be able to access Jupyter Hub from all the computers connected to the network, you have to configure the external access for Jupyter Hub.

First, create a new Jupyter Hub configuration file like “01-external-access.py” in the “/etc/jupyterhub/config/jupyterhub_config.d/ directory” with the following command:

$ sudo nano /etc/jupyterhub/config/jupyterhub_config.d/01-external-access.py

Once the new configuration file “01-external-access.py” is created and opened with the nano text editor, type in the following line of code and press <Ctrl> + X followed by “Y” and <Enter> to save the file:

c.JupyterHub.hub_ip = '0.0.0.0'

A screenshot of a computer Description automatically generated

Restarting the Jupyter Hub Service on Ubuntu 22.04 LTS

For the changes to take effect, restart the Jupyter Hub “systemd” service with the following command:

$ sudo systemctl restart jupyterhub.service

To check the status of the Jupyter Hub “systemd” service, run the following command:

$ sudo systemctl status jupyterhub.service

As you can see, the Jupyter Hub “systemd” service is running[1] and it’s configured to automatically start when your Ubuntu 22.04 LTS machine boots[2].

Accessing Jupyter Hub from the Web Browser

To access Jupyter Hub from other computers on the network, you need to know the IP address or DNS name of your Ubuntu 22.04 LTS system where you have Jupyter Hub installed.

To find the IP address of your Ubuntu 22.04 LTS machine, run the following command:

$ ip a

In our case, the IP address of our Ubuntu 22.04 LTS machine is 192.168.189.128. It will be different for you, so make sure to replace it with yours from now on.

A screenshot of a computer Description automatically generated

Jupyter Hub listens on HTTP port 8000. To access Jupyter Hub from a web browser, visit http://192.168.189.128:8000

Here, 192.168.189.128 is the IP address of our Ubuntu 22.04 LTS machine where we installed Jupyter Hub. Replace it with the IP address of your Ubuntu machine.

Once you see the Jupyter Hub login page, type in the login username and password of your Ubuntu machine and click on “Sign In”.

NOTE: You can log in with any user account of your Ubuntu machine and each user will have their own isolated Jupyter Hub environment. To create a new Jupyter Hub account, just create a new user on your Ubuntu 22.04 LTS machine.

A screenshot of a computer Description automatically generated

Once you’re logged in, you should see the HOME directory of your login user. You can create, delete, or rename the directories or files in your HOME directory from Jupyter Hub and keep your projects organized the way you want.

A screenshot of a computer Description automatically generated

Creating/Uploading a Jupyter Notebook from Jupyter Hub Web Interface

To keep the files of your project organized, it’s a good idea to store each project in a separate directory/folder.

To create a new directory/folder from the Jupyter Hub web UI, click on New > Folder as marked in the following screenshot:

A screenshot of a computer Description automatically generated

A new “Untitled Folder” directory/folder should be created. To rename the newly created directory/folder, select it and click on “Rename” as marked in the following screenshot:

A screenshot of a computer Description automatically generated

Type in a new name for the directory/folder[1] and click on “Rename” to save the changes[2].

A screenshot of a computer Description automatically generated

The directory/folder should be renamed.

Click on it to navigate to the new directory/folder.

A screenshot of a computer Description automatically generated

If you already have a Jupyter Notebook file and you want to work on that, click on “Upload” to upload it to Jupyter Hub.

A screenshot of a computer Description automatically generated

If you don’t have a Jupyter Notebook file and you want to create one, click on New > Python 3 (ipykernel) as marked in the following screenshot:

A screenshot of a computer Description automatically generated

A new untilted Jupyter Notebook should be created. To rename the Jupyter Notebook, click on “Untitled” as marked in the following screenshot:

A screenshot of a computer Description automatically generated

Type in a new name for the Jupyter Notebook and click on “Rename” to save the changes.

A screenshot of a computer Description automatically generated

The Jupyter Notebook should be renamed.

A screenshot of a computer Description automatically generated

You can use Jupyter Notebook to learn to program or try out new ideas as you usually do with Jupyter Notebooks elsewhere.

A screenshot of a computer Description automatically generated

Conclusion

In this article, we showed you how to install Jupyter Hub on Ubuntu 22.04 LTS. We also showed you how to configure the external access to Jupyter Hub on Ubuntu 22.04 LTS so that the other computers on the network can access it. Finally, we showed you how to access Jupyter Hub from a web browser and how to create your first Jupyter Notebook on Jupyter Hub.

About the author

Shahriar Shovon

Freelancer & Linux System Administrator. Also loves Web API development with Node.js and JavaScript. I was born in Bangladesh. I am currently studying Electronics and Communication Engineering at Khulna University of Engineering & Technology (KUET), one of the demanding public engineering universities of Bangladesh.