WSL2 Ubuntu Jupyter Colab
| |

Guide to Installing WSL2, Ubuntu 22.04 LTS, Anaconda, Jupyter Notebook and connect to Colab

In the dynamic realm of technology, establishing a robust development environment is paramount. This guide is tailored to walk you through the seamless setup of WSL2, Ubuntu 22.04 LTS, Anaconda, and Jupyter Notebook on a Windows machine, offering a local resource alternative to platforms like Google Colab.

Prerequisites: 

Before embarking on the installation journey, ensure the following prerequisites are met: 

  • Windows 10 with version 2004 or later (verify in “Settings” -> “System” -> “About”). 
  • Administrator privileges on your Windows machine. 
  • A stable internet connection. 

Part 1: Install WSL2 and Ubuntu 22.04 LTS 

Initiate the process by enabling WSL2 and installing Ubuntu 22.04 LTS: 

  • Enable WSL2 by launching PowerShell as an administrator and executing the provided command. Subsequently, restart your computer. 
  • Install the WSL Kernel by accessing the Microsoft Store and installing the “Ubuntu” app (version 2). 

Now, set up Ubuntu by opening the app from the Start menu and follow the on-screen instructions to create a username and password for your Ubuntu environment. 

Install a Secure VNC Connection 

While VNC offers convenience, be mindful of its security risks, proceed with caution.

Install the VNC server in your Ubuntu terminal using the command:

sudo apt update && sudo apt install vnc4server
vncpasswd
# Set a password for VNC access
vncserver -geometry 1920x1080 :1 (adjust resolution as needed)
# Start VNC server on display :1

Optionally, configure your firewall with specific rules to allow VNC access only from trusted IP addresses. 

Download Anaconda installer:

Visit https://www.anaconda.com/products/distribution and download the Python 3 installer for Linux x86_64.

wget https://repo.anaconda.com/archive/Anaconda3-2023.09-0-Linux-x86_64.sh

Install Anaconda:

Open your Ubuntu terminal and make the downloaded file executable:

chmod +x Anaconda3-2023.19-0-Linux-x86_64.sh

Run the installer Follow the on-screen instructions, opting for the default installation directory unless you have specific needs.

./Anaconda3-2023.11-Linux-x86_64.sh

Set up Jupyter Notebook:

In your terminal, type:

conda activate base

Install Jupyter Notebook:

conda install jupyter

Start Jupyter Notebook:

jupyter notebook

Access Jupyter Notebook through VNC:

  • Open your VNC client and connect to your Ubuntu machine using the VNC server address and port (e.g., localhost:5900).
  • In the VNC session, open a web browser and navigate to http://localhost:8888 (or the URL displayed in your terminal when starting Jupyter Notebook).
  • Enter the VNC password when prompted.

Enhance your Jupyter Notebook environment by following these additional steps: 

Install jupyter_http_over_ws: If not done previously, install the extension in your Jupyter Notebook environment using pip.

pip install jupyter_http_over_ws 

Start Jupyter Notebook with WebSocket connections: Launch your Jupyter Notebook server with the necessary flags to enable WebSocket connections for Colab.

jupyter notebook --allow-root --no-browser --WebSocketURL=ws://localhost:8888 

Flags breakdown:

  • –allow-root: Grants necessary permissions (use with caution!). 
  • –no-browser: Prevents automatic browser launch by Jupyter. 
  • –WebSocketURL=ws://localhost:8888: Specifies the WebSocket URL (adjust port if different). 

Get the WebSocket URL: Look for the URL printed in your terminal output after starting the server, beginning with ws://localhost:8888 (adjust port if different).

Connect to Local Runtime in Colab

  • In your Colab notebook, click the “Connect” button in the top right corner. 
  • Select “Connect to local runtime…” 
  • Paste the WebSocket URL obtained when launching Jupyter Notebook 3 and click “Connect.” 

Secure Your Connection (Optional): While VNC used in the previous guide is convenient, it comes with security risks. Consider alternative methods like SSH for better security

Creating a secure and efficient development environment is an exciting venture. Embrace your newfound Linux development environment, keeping security at the forefront of your exploration. 

  • Security First: Prioritize security when configuring VNC and WebSocket connections; explore alternatives like SSH. 
  • Flexibility and Options: Adjust the guide based on system configurations and personal preferences. 
  • Ongoing Learning: Refer to official documentation for continuous learning and troubleshooting. 
  • Enjoy the Journey: Have fun exploring and unleashing the potential of your Linux development environment. 

Embark on the journey of transforming your Windows machine into a Linux development powerhouse. Explore, learn, and enjoy the possibilities that WSL2, Ubuntu 22.04 LTS, Anaconda, and Jupyter Notebook bring to your fingertips. 

Similar Posts