Table of Contents
System Requirements for Ubuntu 24.04
Step 1: Install Python on Ubuntu
Step 2: Install Git on Ubuntu
Step 3: Set Up a Virtual Environment in Ubuntu
Step 4: Install AI Libraries on Ubuntu
Install TensorFlow in Ubuntu
Install Keras in Ubuntu
Install PyTorch in Ubuntu
Step 5: Building Your First AI Model
Step 6: Run the AI Model
Conclusion
Home System Tutorial LINUX How to Set Up Your Linux System for AI Development

How to Set Up Your Linux System for AI Development

May 07, 2025 am 10:55 AM

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
Copy after login

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

sudo apt update
sudo apt install python3
Copy after login

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

sudo apt install python3-pip
Copy after login

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
Copy after login

Verify the installation by typing:

git --version
Copy after login

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

How to Set Up Your Linux System for AI Development

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
Copy after login

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
Copy after login

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

How to Set Up Your Linux System for AI Development

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
Copy after login

How to Set Up Your Linux System for AI Development

Install Keras in Ubuntu

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

pip3 install keras
Copy after login

How to Set Up Your Linux System for AI Development

Install PyTorch in Ubuntu

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

pip3 install torch
Copy after login

How to Set Up Your Linux System for AI Development

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
Copy after login

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
Copy after login

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()
Copy after login

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
Copy after login

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)
])
Copy after login

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'])
Copy after login

Train the model using the training data.

model.fit(train_images, train_labels, epochs=5)
Copy after login

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)
Copy after login

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
Copy after login

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.

How to Set Up Your Linux System for AI Development

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.

The above is the detailed content of How to Set Up Your Linux System for AI Development. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1267
29
C# Tutorial
1239
24
What is the most use of Linux? What is the most use of Linux? Apr 09, 2025 am 12:02 AM

Linux is widely used in servers, embedded systems and desktop environments. 1) In the server field, Linux has become an ideal choice for hosting websites, databases and applications due to its stability and security. 2) In embedded systems, Linux is popular for its high customization and efficiency. 3) In the desktop environment, Linux provides a variety of desktop environments to meet the needs of different users.

How to learn Linux basics? How to learn Linux basics? Apr 10, 2025 am 09:32 AM

The methods for basic Linux learning from scratch include: 1. Understand the file system and command line interface, 2. Master basic commands such as ls, cd, mkdir, 3. Learn file operations, such as creating and editing files, 4. Explore advanced usage such as pipelines and grep commands, 5. Master debugging skills and performance optimization, 6. Continuously improve skills through practice and exploration.

Does the internet run on Linux? Does the internet run on Linux? Apr 14, 2025 am 12:03 AM

The Internet does not rely on a single operating system, but Linux plays an important role in it. Linux is widely used in servers and network devices and is popular for its stability, security and scalability.

What are Linux operations? What are Linux operations? Apr 13, 2025 am 12:20 AM

The core of the Linux operating system is its command line interface, which can perform various operations through the command line. 1. File and directory operations use ls, cd, mkdir, rm and other commands to manage files and directories. 2. User and permission management ensures system security and resource allocation through useradd, passwd, chmod and other commands. 3. Process management uses ps, kill and other commands to monitor and control system processes. 4. Network operations include ping, ifconfig, ssh and other commands to configure and manage network connections. 5. System monitoring and maintenance use commands such as top, df, du to understand the system's operating status and resource usage.

What is the salary of Linux administrator? What is the salary of Linux administrator? Apr 17, 2025 am 12:24 AM

The average annual salary of Linux administrators is $75,000 to $95,000 in the United States and €40,000 to €60,000 in Europe. To increase salary, you can: 1. Continuously learn new technologies, such as cloud computing and container technology; 2. Accumulate project experience and establish Portfolio; 3. Establish a professional network and expand your network.

What are the main tasks of a Linux system administrator? What are the main tasks of a Linux system administrator? Apr 19, 2025 am 12:23 AM

The main tasks of Linux system administrators include system monitoring and performance tuning, user management, software package management, security management and backup, troubleshooting and resolution, performance optimization and best practices. 1. Use top, htop and other tools to monitor system performance and tune it. 2. Manage user accounts and permissions through useradd commands and other commands. 3. Use apt and yum to manage software packages to ensure system updates and security. 4. Configure a firewall, monitor logs, and perform data backup to ensure system security. 5. Troubleshoot and resolve through log analysis and tool use. 6. Optimize kernel parameters and application configuration, and follow best practices to improve system performance and stability.

Boost Productivity with Custom Command Shortcuts Using Linux Aliases Boost Productivity with Custom Command Shortcuts Using Linux Aliases Apr 12, 2025 am 11:43 AM

Introduction Linux is a powerful operating system favored by developers, system administrators, and power users due to its flexibility and efficiency. However, frequently using long and complex commands can be tedious and er

What is the main purpose of Linux? What is the main purpose of Linux? Apr 16, 2025 am 12:19 AM

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

See all articles