DEV Community

Gabriel Lavoura
Gabriel Lavoura

Posted on • Edited on

3 2 2 2

How to Setup Ollama on Google Colab

Ok, this is just another "how-to on Google Colab" tutorial... but the purpose of this post is more like a note for my future self.

Step 1 - Install colab-xterm

First, we need to have access to a terminal within the Google Colab code cell. This way, we can install Ollama using the shell script approach.

!pip install colab-xterm  
%load_ext colabxterm
Enter fullscreen mode Exit fullscreen mode

This script will install the colab-xterm package (Perhaps an awesome tool! Thanks @popcornylu, you're awesome!), which allows us to use a terminal within our Colab notebook, even on the free tier.

thanks mr. popcornylu, applauses

Step 2 - Open a terminal and install Ollama

To open a terminal, just run the following command in a new cell:

%xterm
#curl -fsSL https://ollama.com/install.sh | sh
#ollama serve & ollama pull llama3.2
Enter fullscreen mode Exit fullscreen mode

Then, paste the curl and ollama commands into the terminal and wait. Once it finishes, you're done!

Step 3 - Test the environment

Create a new cell and run:

!ollama list
Enter fullscreen mode Exit fullscreen mode

If everything is good, it should return the name, ID, size, and last modified date of the model, as shown in the image below.

A screenshot from Google Colab showing the result of ollama list

At this point, you should have a running Ollama server with the Llama3.2:latest model (with 3B parameters) ready to be used.

Step 4 - Clear

Once your session is over, you might want to remove Ollama models to free up space, so create a new cell and run:

!rm -rf /usr/local/bin/ollama
Enter fullscreen mode Exit fullscreen mode

And it's done!

A looney tunes gif with the

PS: A note from the past: you're welcome, future Gabriel! :)

Heroku

Amplify your impact where it matters most — building exceptional apps.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

If you found this post useful, please drop a ❤️ or a friendly comment!

Okay.