RHEL BasedRocky Linux

How To Install Jupyter Notebook on Rocky Linux 9

Install Jupyter Notebook on Rocky Linux 9

Jupyter Notebook has revolutionized the way data scientists, researchers, and developers work with interactive computing environments. This powerful tool allows users to create and share documents containing live code, equations, visualizations, and narrative text. If you’re running Rocky Linux 9 and want to harness the power of Jupyter Notebook, you’ve come to the right place. This comprehensive guide will walk you through the process of installing and configuring Jupyter Notebook on your Rocky Linux 9 system.

Understanding Jupyter Notebook and Rocky Linux 9

Before we dive into the installation process, let’s briefly discuss what Jupyter Notebook is and why Rocky Linux 9 is an excellent choice for hosting it.

What is Jupyter Notebook?

Jupyter Notebook is an open-source web application that allows you to create and share documents containing live code, equations, visualizations, and narrative text. It supports multiple programming languages, including Python, R, and Julia, making it a versatile tool for data analysis, scientific computing, and machine learning.

Why Rocky Linux 9?

Rocky Linux 9 is a community-driven, enterprise-grade operating system designed to be 100% bug-for-bug compatible with Red Hat Enterprise Linux (RHEL). Its stability, security features, and long-term support make it an ideal platform for hosting Jupyter Notebook, especially in production environments.

Prerequisites

Before we begin the installation process, ensure that you have the following:

  • A server or machine running Rocky Linux 9
  • Root or sudo access to the system
  • A stable internet connection
  • Basic familiarity with the Linux command line

Step 1: Update Your System

As with any installation process, it’s crucial to start with an up-to-date system. Open your terminal and run the following command:

sudo dnf update -y

This command will update all installed packages to their latest versions, ensuring compatibility and security.

Step 2: Install Python and Pip

Jupyter Notebook requires Python to run. Rocky Linux 9 comes with Python 3 pre-installed, but we’ll need to install pip, Python’s package manager. Execute the following commands:

sudo dnf install python3 python3-pip -y

Verify the installation by checking the Python and pip versions:

python3 --version
pip3 --version

Step 3: Create a Virtual Environment (Optional but Recommended)

While not strictly necessary, creating a virtual environment for Jupyter Notebook is a best practice. It allows you to manage dependencies separately from your system-wide Python installation. Here’s how to set it up:

python3 -m venv jupyter_env
source jupyter_env/bin/activate

Your prompt should now change to indicate that you’re working within the virtual environment.

Step 4: Install Jupyter Notebook

With Python and pip ready, we can now install Jupyter Notebook. Run the following command:

pip3 install notebook

This command will download and install Jupyter Notebook along with its dependencies.

Step 5: Configure Jupyter Notebook

Now that Jupyter Notebook is installed, we need to configure it for secure access. First, generate a configuration file:

jupyter notebook --generate-config

This command creates a configuration file at ~/.jupyter/jupyter_notebook_config.py.

Setting Up a Password

For security reasons, it’s essential to set up a password for accessing your Jupyter Notebook. Run the following command:

jupyter notebook password

You’ll be prompted to enter and confirm a password. This password will be required when you access Jupyter Notebook through a web browser.

Step 6: Configure Firewall

If you’re running a firewall on your Rocky Linux 9 system (which is recommended), you’ll need to open the port that Jupyter Notebook uses. By default, this is port 8888. Use the following commands to open this port:

sudo firewall-cmd --add-port=8888/tcp --permanent
sudo firewall-cmd --reload

Step 7: Start Jupyter Notebook

You’re now ready to start Jupyter Notebook. If you want to run it on your local machine, simply execute:

jupyter notebook

However, if you’re running Jupyter Notebook on a remote server and want to access it from another machine, use the following command:

jupyter notebook --ip 0.0.0.0 --no-browser

This command starts Jupyter Notebook, binding it to all network interfaces, and prevents it from automatically opening a browser window.

Step 8: Accessing Jupyter Notebook

To access your Jupyter Notebook installation:

  1. Open a web browser on your local machine.
  2. Enter the URL: http://your_server_ip:8888 (replace your_server_ip with your actual server IP address).
  3. Enter the password you set earlier when prompted.

You should now see the Jupyter Notebook interface, where you can create new notebooks or open existing ones.

Install Jupyter Notebook on Rocky Linux 9

Advanced Configuration

For a more robust setup, especially in production environments, you might want to run Jupyter Notebook as a system service. This ensures that it starts automatically on system boot and runs in the background. Here’s how to set this up:

Create a Service File

Create a new file named jupyter.service in the /etc/systemd/system/ directory:

sudo nano /etc/systemd/system/jupyter.service

Add the following content to the file:

[Unit]
Description=Jupyter Notebook

[Service]
Type=simple
PIDFile=/run/jupyter.pid
ExecStart=/usr/local/bin/jupyter-notebook --config=/home/your_username/.jupyter/jupyter_notebook_config.py
User=your_username
Group=your_username
WorkingDirectory=/home/your_username/notebooks
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target

Replace your_username with your actual username and adjust paths as necessary.

Enable and Start the Service

After creating the service file, enable and start it with these commands:

sudo systemctl enable jupyter.service
sudo systemctl start jupyter.service

You can check the status of the service at any time using:

sudo systemctl status jupyter.service

Troubleshooting Common Issues

Even with careful installation, you might encounter some issues. Here are solutions to common problems:

Jupyter Command Not Found

If you receive a “command not found” error when trying to run Jupyter Notebook, ensure that it’s installed correctly and that your PATH is set up properly. Try running:

which jupyter

If this doesn’t return a path, you may need to add the Python bin directory to your PATH.

Port Already in Use

If you see an error message saying the port is already in use, you can either stop the process using that port or configure Jupyter to use a different port. To use a different port, modify your command to:

jupyter notebook --port=8889

Connection Refused

If you’re trying to access Jupyter Notebook remotely and get a “Connection Refused” error, double-check your firewall settings and ensure that you’ve started Jupyter with the --ip 0.0.0.0 option.

Enhancing Your Jupyter Notebook Experience

Now that you have Jupyter Notebook up and running on your Rocky Linux 9 system, consider these tips to enhance your experience:

Install Additional Kernels

While Python is the default kernel, Jupyter supports many other programming languages. For example, to add support for R, you can install the IRkernel:

sudo dnf install R
R
> install.packages('IRkernel')
> IRkernel::installspec(user = FALSE)

Explore Jupyter Extensions

Jupyter has a rich ecosystem of extensions that can enhance its functionality. You can explore and install extensions using the Jupyter Nbextensions Configurator:

pip install jupyter_contrib_nbextensions
jupyter contrib nbextension install --user
pip install jupyter_nbextensions_configurator
jupyter nbextensions_configurator enable --user

Version Control Integration

Consider integrating your Jupyter notebooks with version control systems like Git. This can be particularly useful for collaborative projects and maintaining a history of your work.

Congratulations! You have successfully installed Jupyter. Thanks for using this tutorial for installing the Jupyter Notebook on your Rocky Linux 9 system. For additional help or useful information, we recommend you check the official Jupyter website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button