Jupyter Notebook

How to Install JupyterHub Bash Kernel to Run Bash Codes on Jupyter Notebooks

The programming language support comes as kernels on JupyterHub. The Python kernel comes installed by default on JupyterHub which enables the Python programming language on Jupyter Notebooks. You can use other programming languages on your Jupyter Notebooks as well. All you have to do is install the appropriate kernels for JupyterHub on your computer.

In this article, we will show you how to install the JupyterHub Bash kernel on your JupyterHub server so that the JupyterHub users can run the Bash codes on their Jupyter Notebooks.

NOTE: If you don’t have JupyterHub installed on your computer, you can read one of the following articles depending on the Linux distribution that you’re using:

1. How to Install the Latest Version of JupyterHub on Ubuntu 22.04 LTS/ Debian 12/Linux Mint 21

2. How to Install the Latest Version of JupyterHub on Fedora 38+/RHEL 9/Rocky Linux 9

Topic of Contents:

  1. Installing JupyterHub Bash Kernel for a Single User
  2. Installing JupyterHub Bash Kernel for All Users
  3. Conclusion
  4. References

Installing JupyterHub Bash Kernel for a Single User

If you’re a JupyterHub user and you don’t have super-user (root) privileges, you can install the Bash kernel on Jupyter Hub only for your JupyterHub account.

First, log in to your JupyterHub account and click on “Terminal” from the “Launcher” tab.

You should be able to access Python PIP on the terminal.

$ pip3 --version

To install the JupyterHub Bash kernel Python module, run the following command:

$ pip3 install bash_kernel

The JupyterHub Bash kernel Python module is being installed. It takes a while to complete.

At this point, the JupyterHub Bash kernel Python module should be installed.

To install the JupyterHub Bash kernel for your JupyterHub account, run the following command:

$ python3 -m bash_kernel.install

For the changes to be visible, refresh the JupyterHub homepage and you should see “Bash” in the “Notebook” section of JupyterHub. Click on it to create a Bash Jupyter Notebook.

A new Jupyter Notebook should be created and the Bash kernel should be selected for the notebook.

You can run and document the Bash codes in this notebook in the same way as you do in Python codes.

Installing JupyterHub Bash Kernel for All Users

If you have administrative privileges on the JupyterHub server, you can install the JupyterHub Bash kernel for all the JupyterHub users. This saves a lot of hassle for the JupyterHub users as well as save a lot of disk space and reduce the data redundancy on the JupyterHub server.

To install the JupyterHub Bash kernel Python module on the JupyterHub virtual environment, run the following command:

$ sudo /opt/jupyterhub/bin/python3 -m pip install bash_kernel

The JupyterHub Bash kernel Python module should be installed on the JupyterHub virtual environment.

To install the JupyterHub Bash kernel (on the JupyterHub virtual environment) for all the JupyterHub users, run the following command:

$ sudo /opt/jupyterhub/bin/python3 -m bash_kernel.install

As you can see, the JupyterHub Bash kernel is installed.

$ sudo /opt/jupyterhub/bin/jupyter-kernelspec list

Now, any JupyterHub user can find an option to create the Bash notebooks on the JupyterHub “Launcher” tab.

To create a Bash Jupyter notebook, click on “Bash” from the “Notebook” section of the JupyterHub “Launcher” tab.

A Bash Jupyter notebook should be created.

You can run and document the Bash codes in this notebook in the same way as you do in Python codes.

Conclusion

In this article, we showed you how to install the JupyterHub Bash kernel on your JupyterHub server so that the JupyterHub users can run and document the Bash codes on their Jupyter Notebooks just as they do in Python codes.

References:

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.