Run DeepSeek-R1 Locally: A Python & Linux Guide

Updated on Sep 30,2025

Table of Contents

This guide delves into the process of locally setting up and executing the DeepSeek-R1 model using Python and Linux. As interest in large language models (LLMs) continues to rise, understanding how to deploy and utilize them locally becomes increasingly essential. This machine learning article provides step-by-step instructions and essential insights to get you started with DeepSeek-R1, a reasoning model that performs exceptionally well in complex problem-solving scenarios.

Key Points

DeepSeek-R1 is a reasoning model, excelling in complex reasoning tasks compared to classical LLMs.

The DeepSeek-R1 model is comparable to the performance of OpenAI-01 but released under the MIT license, allowing commercial use.

Distilled models like DeepSeek-R1-32B offer reduced disk space requirements without significant performance loss.

Using Ollama simplifies the process of downloading and running large language models locally.

A virtual environment is recommended to isolate project dependencies.

Understanding DeepSeek-R1

What is DeepSeek-R1?

DeepSeek-R1 is a large language model categorized as a reasoning model. Reasoning models, like DeepSeek-R1, showcase superior performance when tackling complex reasoning problems and tasks, particularly those found in areas like mathematics, science, and coding. This makes DeepSeek-R1 a valuable tool for applications requiring intricate problem-solving capabilities.

Unlike many proprietary LLMs, DeepSeek-R1 is released under the MIT license. This is important because it grants users the freedom to utilize, modify, and distribute the model, even in commercial settings, without restrictive licensing constraints. This open-source approach is a significant advantage, fostering innovation and wider adoption of the model.

DeepSeek also provides distilled models of DeepSeek-R1. While the full DeepSeek-R1 model demands substantial computational resources (over 400GB of disk space), distilled models offer a solution by reducing the model size without drastically impacting performance. These compressed models, ranging from 1.5 to 70 billion parameters, make DeepSeek-R1 more accessible for users with limited hardware capabilities.

Licensing Advantages of DeepSeek-R1

The MIT license is a permissive free software license, meaning it places minimal restrictions on how the software is used, modified, and distributed. DeepSeek-R1's open nature, enabled by the MIT license, opens doors for businesses to integrate this powerful model into their products and services without incurring significant licensing costs. This contrasts sharply with other models that require expensive subscriptions or usage fees, enabling the usage of this large language model in a commercial setting.

Reasoning Models versus Classical Large Language Models

Traditional Large Language Models are proficient at various tasks, including text generation, translation, and summarization. However, they sometimes falter when confronted with problems requiring deep reasoning and logical thinking. Reasoning models, such as DeepSeek-R1, are specifically engineered to excel in these demanding scenarios. They employ advanced algorithms and architectures that allow them to dissect complex problems, identify underlying patterns, and arrive at logical solutions. The ability to handle mathematical proofs, understand scientific concepts, and generate complex code snippets underscores the unique power and capabilities of reasoning models like DeepSeek-R1.

Essential Prerequisites for Local Installation

Hardware and Software Requirements

Before embarking on the installation process, verifying your system's compatibility with the requirements of DeepSeek-R1 is important.

  • Operating System: This guide focuses on Linux Ubuntu.
  • Processor: An Intel i9 processor is recommended for optimal performance.
  • RAM: At least 64 GB of RAM is recommended for decent usage.
  • GPU: NVIDIA 3090 GPU with 24GB VRAM will allow you to run this software.
  • Disk Space: A significant amount of disk space (1 to 40 GB for distilled models) is required. 400 GB - 1TB may be required for other models.

Open the Required Port for proper functioning

Opening the right port is critical for the smooth operation of DeepSeek-R1.

The port referenced (11434) allows the Ollama server to be executed. This is a really vital step, the port must be open for local and outside connections.

Step-by-Step Installation and Usage Guide

Step 1: Installing Curl & Ubuntu Updates

The first thing you need to do is install Curl and Ubuntu updates to use DeepSeek R1.

Curl is a command-line tool used for transferring data with URLs, which is required for downloading necessary components. Before installing Curl, update your Ubuntu repositories to ensure you have the latest package information.

sudo apt update && sudo apt upgrade

After updating, install Curl:

sudo apt install curl

Verify the installation by checking the Curl version:

curl --version

Step 2: Installing Ollama

Ollama simplifies the process of running LLMs locally. Install Ollama by navigating to the official website (ollama.com) and downloading the Linux version. Once downloaded, open your terminal and use the provided command to install Ollama:

curl -fsSL https://ollama.com/install.sh | sh

This command downloads and executes the Ollama installation script.

Step 3: Downloading DeepSeek-R1 Model with Ollama

Next, download the DeepSeek-R1 model using Ollama. First, search for DeepSeek-R1 on the Ollama website. Then, select the appropriate model version (e.g., a distilled model with 32B parameters to keep your hardware compatible) and click the 'Run' command on the screen to obtain the specific pull command.

Important Note: Do not execute this command directly. To ensure proper downloading, modify the command.

Use the ollama pull command followed by the model name, as shown below:

ollama pull deepseek-r1:14b

This command downloads the DeepSeek-R1 14b parameter model to your local system. This may take some time, depending on your internet connection speed.

Step 4: Creating a Python Virtual Environment

A virtual environment helps isolate project dependencies. Create a new directory for your project, navigate into it, and then create a virtual environment:

mkdir testModel
cd testModel

Install the virtual environment package:

sudo apt install python3.12-venv #Ensure your python version is compatible with this command, replace 3.12 with your version

Create the python virutal environment:

python3 -m venv env1 #env1 is the environment name, name as you desire

Activate the virtual environment:

source env1/bin/activate

Your terminal Prompt should now show the virtual environment name (env1).

Step 5: Installing the Ollama Python Library

With the virtual environment activated, install the Ollama Python library:

pip install ollama

This command installs the necessary Python bindings to interact with the Ollama server and run the DeepSeek-R1 model from Python scripts.

Step 6: Creating and Running the Python Script

Create a Python script (e.g., test.py) using Nano or any other text editor:

sudo nano test.py

Add the following code to the script. Remember to modify the desiredModel variable to match the DeepSeek-R1 model version you downloaded. This code snippet prompts the model to give a solution to a quadratic equation, saves the output to a text file, and then prints it to the terminal.

import ollama

desiredModel='deepseek-r1:14b'
questionToAsk='How to solve a quadratic equation x^2+5*x+6=0'

response = ollama.chat(model=desiredModel, messages=[
    {
        'role': 'user',
        'content': questionToAsk,
    },
])

OllamaResponse=response['message']['content']

print(OllamaResponse)

with open("OutputOllama.txt", "w", encoding="utf-8") as text_file:
    text_file.write(OllamaResponse)

Run the Python script:

sudo python3 test.py

Understanding Costs and Access

Cost Considerations

Running DeepSeek-R1 locally shifts the expense from licensing fees to hardware investments and energy consumption. While the model itself is available under the MIT license, the cost of powerful GPUs, sufficient RAM, and adequate storage capacity needs to be factored in. Moreover, operating such resource-intensive models results in increased electricity consumption, which should be accounted for to accurately assess the overall financial impact.

Weighing the Advantages and Disadvantages of DeepSeek-R1

👍 Pros

Strong reasoning capabilities

Commercial license (MIT)

Availability of distilled models

Good community support

👎 Cons

High hardware requirements for the full model

Resource-intensive operation.

Complicated installation for unexperienced developers

Frequently Asked Questions

What is a distilled LLM?
A distilled large language model refers to a compressed or streamlined version of a larger language model. This compression is achieved through techniques like knowledge distillation, where a smaller 'student' model is trained to mimic the behavior and performance of a more extensive 'teacher' model. Distilled models retain a significant portion of the original model's capabilities while demanding fewer computational resources, making them ideal for deployment in resource-constrained environments. They represent a trade-off between model size, computational efficiency, and overall performance.
Does DeepSeek R1 Work with Apple Silicon?
While this guide focuses on Linux Ubuntu, Ollama offers compatibility across various platforms including macOS. The underlying installation process remains mostly consistent, but minor command variations may be needed. When running DeepSeek-R1 on Apple Silicon, you can greatly benefit from the silicon's Neural Engine, resulting in accelerated performance and optimized energy efficiency.

Related Questions

How does DeepSeek-R1 compare to other LLMs in terms of performance?
As noted in the article, DeepSeek-R1's performance is considered on par with OpenAI-01, a notable LLM, when doing benchmarks of problem solving. This places DeepSeek-R1 among some of the top performing LLMs. However, it is important to understand that performance can vary significantly based on the specific task and benchmark being used. Also, it is important to highlight that the distilled model and full model are 2 very different levels of performance.
How can I optimize DeepSeek-R1's performance on limited hardware?
If you have limited hardware you can optimize DeepSeek-R1 performance by using a distilled model. Other things you can do are quantize the model, reduce the number of layers, and optimize batch sizes to reduce memory usage. Experiment with different configurations to find the optimal balance for your specific hardware setup.

Most people like