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 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. 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 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 If everything is good, it should return the name, ID, size, and last modified date of the model, as shown in the image below. 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 And it's done! PS: A note from the past: you're welcome, future Gabriel! :)

Mar 11, 2025 - 06:10
 0
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

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

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

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

And it's done!

A looney tunes gif with the

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