Beginner’s Guide to Setting Up AI Development Environment on Linux

In the previous article, we introduced the basics of AI and how it fits into the world of Linux. Now, it’s time to dive deeper and set up your Linux system to start building your first AI model.

Whether you’re a complete beginner or have some experience, this guide will walk you through installing the essential tools you need to get started on Debian-based systems.

System Requirements for Ubuntu 24.04

Before we begin, let’s make sure your system meets the minimum requirements for AI development.

  • Operating System: Ubuntu 24.04 LTS (or newer).
  • Processor: A 64-bit CPU with at least 2 cores (Intel Core i5 or AMD Ryzen 5 or better recommended for smooth performance).
  • RAM: Minimum 4 GB of RAM (8 GB or more recommended for more intensive AI models).
  • Storage: At least 10 GB of free disk space (SSD is highly recommended for faster performance).
  • Graphics Card (Optional): A dedicated GPU (NVIDIA recommended for deep learning) with at least 4 GB of VRAM if you plan to use frameworks like TensorFlow or PyTorch with GPU acceleration.

Step 1: Install Python on Ubuntu

Python is the most popular programming language for AI development, due to its simplicity, powerful, and huge library of tools and frameworks.

Most Linux systems come with Python pre-installed, but let’s make sure you have the latest version. If Python is installed, you’ll see something like Python 3.x.x.

python3 --version

If Python is not installed, you can easily install it using the package manager.

sudo apt update
sudo apt install python3

Next, you need to install pip (python package manager), which will help you install and manage Python libraries.

sudo apt install python3-pip

Step 2: Install Git on Ubuntu

Git is a version control tool that allows you to track changes in your code and collaborate with others, which is essential for AI development because many AI projects are shared on platforms like GitHub.

sudo apt install git

Verify the installation by typing:

git --version

You should see something like git version 2.x.x.

Install Git in Ubuntu
Install Git in Ubuntu

Step 3: Set Up a Virtual Environment in Ubuntu

A virtual environment helps you manage your projects and their dependencies in isolation, which means you can work on multiple projects without worrying about conflicts between different libraries.

First, make sure you have the python3-venv package installed, which is needed to create a virtual environment.

sudo apt install python3-venv

Next, you need to create a new directory for your project and set up a virtual environment:

mkdir my_ai_project
cd my_ai_project
python3 -m venv venv
source venv/bin/activate

After running the above commands, your terminal prompt should change, indicating that you’re now inside the virtual environment.

Setup Python Virtual Environment
Setup Python Virtual Environment

Step 4: Install AI Libraries on Ubuntu

Now that you have Python, Git, and Virtual Environment set up, it’s time to install the libraries that will help you build AI models.

Some of the most popular libraries for AI are TensorFlow, Keras, and PyTorch.

Install TensorFlow in Ubuntu

TensorFlow is an open-source library developed by Google that is widely used for machine learning and AI projects.

pip3 install tensorflow
Install TensorFlow in Ubuntu
Install TensorFlow in Ubuntu

Install Keras in Ubuntu

Keras is a high-level neural networks API, written in Python, that runs on top of TensorFlow.

pip3 install keras
Install Keras in Ubuntu
Install Keras in Ubuntu

Install PyTorch in Ubuntu

PyTorch is another popular AI library, especially for deep learning.

pip3 install torch
Install PyTorch in Ubuntu
Install PyTorch in Ubuntu

Step 5: Building Your First AI Model

Now that your system is ready, let’s build a simple AI model called a neural network using TensorFlow and Keras to classify handwritten digits from the famous MNIST dataset.

Create a new Python file called first_ai_model.py and open it in your favorite text editor.

sudo nano first_ai_model.py

At the top of the file, add the following imports to import the necessary libraries:

import tensorflow as tf
from tensorflow.keras import layers, models

Next, load the MNIST dataset, which contains 60,000 images of handwritten digits (0-9) to train our model.

(train_images, train_labels), (test_images, test_labels) = tf.keras.datasets.mnist.load_data()

Preprocess the data to normalize the images to values between 0 and 1 by dividing by 255.

train_images, test_images = train_images / 255.0, test_images / 255.0

Build the model by creating a simple neural network with one hidden layer.

model = models.Sequential([
    layers.Flatten(input_shape=(28, 28)),
    layers.Dense(128, activation='relu'),
    layers.Dense(10)
])

Compile the model by specifying the optimizer, loss function, and metrics for evaluation.

model.compile(optimizer='adam',
              loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
              metrics=['accuracy'])

Train the model using the training data.

model.fit(train_images, train_labels, epochs=5)

Finally, test the model on the test data to see how well it performs.

test_loss, test_acc = model.evaluate(test_images, test_labels)
print('Test accuracy:', test_acc)

Step 6: Run the AI Model

Once you’ve written the code, save the file and run it in your terminal:

python3 first_ai_model.py

The model will begin training, and after 5 epochs, it will display the test accuracy. The higher the accuracy, the better the model’s performance.

Run AI Model
Run AI Model

Congratulations, you’ve just built your first AI model!

Conclusion

In this guide, we covered how to set up your Linux system for AI development by installing Python, Git, and essential AI libraries like TensorFlow, Keras, and PyTorch.

We also walked through building a simple neural network to classify handwritten digits. With these tools and knowledge, you’re now ready to explore the exciting world of AI on Linux!

Stay tuned for more articles in this series, where we’ll dive deeper into AI development techniques and explore more advanced topics.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Ravi Saive
I am an experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.