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! :)

API Trace View

How I Cut 22.3 Seconds Off an API Call with Sentry

Struggling with slow API calls? Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more →

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay