CentOSRHEL Based

How to Install Jupyter Notebook on CentOS Stream 10

Install Jupyter Notebook on CentOS Stream 10

Jupyter Notebook is a powerful, browser-based interface for interactive coding, data visualization, and documentation. It is widely used by data analysts, machine learning engineers, and researchers to create and share documents containing live code, equations, visualizations, and narrative text. Running Jupyter Notebook on CentOS Stream 10 can provide a stable and secure environment for both personal projects and enterprise development. This comprehensive guide covers every step—from checking prerequisites and setting up Python to securing remote access and troubleshooting—ensuring a smooth installation and optimal configuration of Jupyter Notebook.

By following this guide, you will learn how to install Jupyter Notebook on CentOS Stream 10, create a dedicated virtual environment, secure your setup with passwords or token-based authentication, and enable remote access if you wish to develop or collaborate over a network. This article also covers strategies to troubleshoot common issues and includes best practices to keep your Jupyter server running efficiently.

Prerequisites

Before beginning the installation, ensure that your CentOS Stream 10 system meets the following prerequisites:

  • CentOS Stream 10 installed: A fresh or existing CentOS Stream 10 instance with administrative or sudo privileges.
  • Stable internet connection: Required to download system updates, Python, and the pip packages needed for Jupyter Notebook.
  • Basic Linux command-line knowledge: Familiarity with the terminal, package managers, and editing configuration files.
  • Python 3 and pip: Jupyter Notebook requires Python 3.3 or later. Pip (Python’s package manager) is important for installing Python packages efficiently.

Most modern CentOS Stream 10 installations already have Python 3 available, but verifying this beforehand prevents installation conflicts. If not, you will learn how to install it in the upcoming steps.

Step 1: Update System Packages

Keeping your system packages current is crucial for security, stability, and compatibility. Outdated or missing dependencies can lead to conflicts during installation. To ensure your system is up to date, run:

sudo dnf update -y
sudo dnf upgrade -y

The -y flag automatically answers “yes” to the prompts, saving time and ensuring that all necessary upgrades are applied. This step is recommended before installing significant software components such as Python or Jupyter Notebook.

Step 2: Install Python and Pip

Jupyter Notebook leverages Python to run interactive code cells. While CentOS Stream 10 typically includes Python 3, you may need to install or update Python explicitly. Below are the commands to install Python 3 and pip:

sudo dnf install -y python3 python3-pip

Verify that both Python and pip have been installed correctly:

python3 --version
pip3 --version

You should see a Python 3.x version number and a pip 20.x or higher version displayed. Optionally, installing the Python development headers can be helpful if certain libraries (like numpy or pandas) require compilation:

sudo dnf install -y python3-devel

This ensures your environment is prepared to build Python packages that require native modules.


Step 3: Set Up a Python Virtual Environment

Using a Python virtual environment allows you to isolate your project dependencies from the system-wide environment. This isolation prevents possible version conflicts and keeps your main operating system environment clean. If you want an easier maintenance and upgrade path, creating a virtual environment is the way to go.

  1. Install the required package to create a virtual environment (if not already installed):
    sudo dnf install -y python3-venv
    
  2. Create a new virtual environment (replace my_env with your preferred name):
    python3 -m venv my_env
    
  3. Activate the virtual environment:
    source my_env/bin/activate
    

    Once activated, your command prompt should begin with something like (my_env), indicating that you are now working within an isolated environment.

When you install any Python packages (including Jupyter Notebook) in this environment, they remain separate from your system-wide libraries.

Step 4: Install Jupyter Notebook

With Python and pip properly set up—preferably within your virtual environment—it’s time to install Jupyter Notebook. This process is straightforward:

pip3 install notebook

If you have activated a virtual environment, use pip instead of pip3, depending on your virtual environment’s setup:

pip install notebook

After installation, confirm it was successful by checking the Jupyter Notebook version:

jupyter notebook --version

A version number such as 6.x or 7.x indicates that Jupyter Notebook has been installed correctly.

If you run into errors like jupyter: command not found, double-check that your PATH environment variable includes your Python or virtual environment’s bin directory. Some users may need to reload their shell or reactivate their virtual environment.

Step 5: Configure Jupyter Notebook

While Jupyter Notebook is now installed, it’s beneficial to configure it for security and convenience. Proper configuration also prevents unauthorized access, especially if you enable remote connections.

Set Up a Password for Secure Access

By default, Jupyter Notebook generates a random token for access. You can set a persistent password:

jupyter notebook password

You will be prompted to enter and verify a password. This ensures that each time you start Jupyter, it will require that password for authentication rather than relying on a token in the URL.

Generate and Edit a Configuration File

Generate the default Jupyter Notebook configuration file inside your home directory. This file is located typically in ~/.jupyter/jupyter_notebook_config.py:

jupyter notebook --generate-config

Open this file in a text editor such as nano or vi:

nano ~/.jupyter/jupyter_notebook_config.py

Look for lines that begin with c.NotebookApp. and customize them according to your needs:

  • IP address (if remote access is needed):
    c.NotebookApp.ip = '0.0.0.0'
  • Port (to change from the default 8888):
    c.NotebookApp.port = 9999
  • Disable browser auto-launch:
    c.NotebookApp.open_browser = False
  • Password protection: This setting is linked to the hashed password you created with jupyter notebook password and typically auto-populated in the config file after the first run.

Make sure you save your changes.

Step 6: Start Jupyter Notebook Locally

With Jupyter Notebook installed and securely configured, you are ready to launch it. Within your virtual environment—or globally if you chose that route—run:

jupyter notebook

By default, this command starts the Jupyter Notebook server on port 8888 and will attempt to open your web browser, pointing to http://localhost:8888. If you configured a password in the previous step, you will need to enter it to access your notebook dashboard.

Install Jupyter Notebook on CentOS Stream 10

Use the notebook dashboard to create, open, or manage your notebooks. The interface makes it easy to start new Python notebooks or manage existing documents.

If you see any issues like “Jupyter Notebook doesn’t load in the browser”, try manually navigating to http://127.0.0.1:8888 or http://localhost:8888 in your web browser, and also confirm your firewall settings or security software are not preventing a local connection.

Step 7: Enable Remote Access to Jupyter Notebook

Remote access is useful if you want to run data-intensive tasks on a server, yet develop from another computer or allow collaboration from multiple users. Configuring Jupyter Notebook for this purpose requires two main steps:

Allow External Connections

Within your Jupyter configuration file jupyter_notebook_config.py, ensure that the ip is set to '0.0.0.0':

c.NotebookApp.ip = '0.0.0.0'
c.NotebookApp.open_browser = False
c.NotebookApp.port = 8888

As a security recommendation, always use a password or token-based authentication when opening Jupyter Notebook to the public internet.

Configure the Firewall

CentOS Stream 10 typically uses firewalld. For remote clients to access Jupyter’s port (e.g., 8888), open it on your firewall:

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

This step ensures inbound connections to TCP port 8888 are allowed.

Access Over SSH Tunneling (Optional)

If exposing the port through your firewall is not desired, or if you want an extra layer of security, you can use SSH tunneling. On your local machine:

ssh -L 9999:localhost:8888 your_user@your_server_ip

Then, open your browser and navigate to http://localhost:9999. This tunnel proxies traffic securely from your local port 9999 to the server’s port 8888, where Jupyter Notebook listens.

Secure Socket Layer (SSL) Encryption

For end-to-end encryption, consider using SSL certificates. Basic steps include generating an SSL certificate (using openssl) and configuring the c.NotebookApp.certfile and c.NotebookApp.keyfile lines in your jupyter_notebook_config.py .

Step 8: Additional Configuration Options

Jupyter Notebook is highly flexible, allowing advanced configuration and extension management.

JupyterLab

JupyterLab is the next-generation interface for Jupyter, offering a more modern, flexible environment. If you prefer that interface, install it using:

pip install jupyterlab

Then launch JupyterLab with:

jupyter lab

While the classic notebook interface remains popular, JupyterLab provides additional features such as drag-and-drop file management, multiple panels, and integrated terminals.

Installing Popular Extensions

Jupyter has an ecosystem of extensions that add functionalities like code formatting, table of contents, or variable inspector panels. A popular extension library is jupyter_contrib_nbextensions:

pip install jupyter_contrib_nbextensions
jupyter contrib nbextension install --user

Once installed, use the Nbextensions tab in your notebook environment to enable or disable features that can boost your productivity.

Step 9: Troubleshooting Common Issues

Despite following the recommended steps, issues might sometimes arise. Here are a few common scenarios and solutions:

jupyter: command not found” Error

This error usually indicates that your PATH does not include where Jupyter is installed. If you’re using a virtual environment, make sure you have run source my_env/bin/activate. For system-wide installations, ensure ~/.local/bin or the global Python bin directory is on your PATH .

Jupyter Notebook Fails to Load in the Browser

If no browser launches automatically, copy and paste the URL token (shown in your terminal) in any web browser. If it still doesn’t work, confirm that no firewall rule or SELinux policy is blocking access to the default port. Also, try switching between localhost and 127.0.0.1.

Access Denied or Network Errors

When remote connections are refused, either the port is not open in the firewall, or your server’s IP address is not properly configured in the Jupyter config file. Double-check the firewall settings and c.NotebookApp.ip line in jupyter_notebook_config.py.

Kernel or Package Import Failures

Sometimes a notebook kernel fails to start, especially if you have installed packages in a different environment. Make sure the kernel is launched from the same Python environment that contains your installed packages. You can select the correct kernel from the Kernel menu in the Jupyter interface or by installing ipykernel in your environment:

pip install ipykernel
python -m ipykernel install --user --name=my_env

Congratulations! You have successfully installed Jupyter. Thanks for using this tutorial for installing the Jupyter Notebook on your CentOS Stream 10 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