DEV Community

Gabriel Lavoura
Gabriel Lavoura

Posted on

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

Top comments (0)