# Setup AnythingLLM Server on Bare Metal Ubuntu

Setting up AnythingLLM on a bare metal server gives you direct control over performance and customization without the overhead of Docker. This guide will walk you through the process of installing and running the AnythingLLM application in production on an Ubuntu server, using **systemd** to manage services.

[https://github.com/Mintplex-Labs/anything-llm/blob/master/BARE\_METAL.md#run-anythingllm-in-production-without-docker](https://github.com/Mintplex-Labs/anything-llm/blob/master/BARE_METAL.md#run-anythingllm-in-production-without-docker)

### Prerequisites

Before we start, ensure your server meets the following requirements:

* At least **2GB of RAM**.
    
* Minimum **10GB of disk space**.
    
* **Node.js v18**.
    
* **Yarn** package manager.
    

### Step 1: Installing Node.js and Yarn

First, you need to install Node.js and Yarn. Follow these steps:

1. **Install Node.js**:
    
    ```plaintext
    curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
    sudo apt-get install -y nodejs
    ```
    
2. **Install Yarn**:
    
    ```plaintext
    npm install --global yarn
    ```
    

Verify the installations:

```plaintext
node -v
yarn -v
```

### Step 2: Clone the AnythingLLM Repository

Next, clone the AnythingLLM repository to your server:

```plaintext
git clone https://github.com/Mintplex-Labs/anything-llm.git
cd anything-llm
```

### Step 3: Install Dependencies

1. Navigate to the `anything-llm` directory and install the necessary dependencies:
    
    ```plaintext
    yarn setup
    ```
    
2. **Prepare the Environment**: Copy the environment file template and adjust paths as needed:
    
    ```plaintext
    cp server/.env.example server/.env
    ```
    
    Set the `STORAGE_DIR` path inside `server/.env`:
    
    ```plaintext
    STORAGE_DIR="/your/absolute/path/to/server/storage"
    ```
    
3. **Edit Frontend Configuration**: Update the frontend `.env` file for production:
    
    ```plaintext
    cd frontend
    nano .env
    ```
    
    Set `VITE_API_BASE='/api'` for proper API routing.
    

### Step 4: Build the Frontend

1. **Build the frontend application**:
    
    ```plaintext
    cd frontend
    yarn build
    ```
    
2. **Move the build files** to the server public directory:
    
    ```plaintext
    cp -R frontend/dist server/public
    ```
    

### Step 5: Set Up the Database

Prepare the SQLite database with the following commands:

```plaintext
cd server
npx prisma generate --schema=./prisma/schema.prisma
npx prisma migrate deploy --schema=./prisma/schema.prisma
```

### Step 6: Run AnythingLLM

Now, you need to start both the server and collector components of AnythingLLM.

1. **Start the Server**:
    
    ```plaintext
    cd server
    NODE_ENV=production node index.js &
    ```
    
2. **Start the Collector**: In a new terminal or SSH session:
    
    ```plaintext
    cd collector
    NODE_ENV=production node index.js &
    ```
    

At this point, AnythingLLM should be running locally on [`http://localhost:3001`](http://localhost:3001). But to keep these processes running and manage them properly, we’ll configure systemd.

---

### Step 7: Setting Up Systemd Services

Using **systemd**, we can ensure that both the server and the collector start automatically on boot and run independently of your SSH session.

#### 1\. Create a Systemd Service for the Server

1. **Create the service file**:
    
    ```plaintext
    sudo nano /etc/systemd/system/anythingllm-server.service
    ```
    
2. **Add the following configuration**:
    
    ```plaintext
    [Unit]
    Description=AnythingLLM Server
    After=network.target
    
    [Service]
    WorkingDirectory=/home/supportlinux/anything-llm/server
    ExecStart=/usr/bin/node index.js
    Environment=NODE_ENV=production
    Restart=always
    RestartSec=10
    User=supportlinux
    Group=supportlinux
    
    [Install]
    WantedBy=multi-user.target
    ```
    
3. **Enable and start the service**:
    
    ```plaintext
    sudo systemctl daemon-reload
    sudo systemctl start anythingllm-server
    sudo systemctl enable anythingllm-server
    ```
    

#### 2\. Create a Systemd Service for the Collector

1. **Create the collector service file**:
    
    ```plaintext
    sudo nano /etc/systemd/system/anythingllm-collector.service
    ```
    
2. **Add the following configuration**:
    
    ```plaintext
    [Unit]
    Description=AnythingLLM Collector
    After=network.target
    
    [Service]
    WorkingDirectory=/home/supportlinux/anything-llm/collector
    ExecStart=/usr/bin/node index.js
    Environment=NODE_ENV=production
    Restart=always
    RestartSec=10
    User=supportlinux
    Group=supportlinux
    
    [Install]
    WantedBy=multi-user.target
    ```
    
3. **Enable and start the collector service**:
    
    ```plaintext
    sudo systemctl daemon-reload
    sudo systemctl start anythingllm-collector
    sudo systemctl enable anythingllm-collector
    ```
    

### Step 8: Verify Both Services

1. **Check the status of the server**:
    
    ```plaintext
    sudo systemctl status anythingllm-server
    ```
    
2. **Check the status of the collector**:
    
    ```plaintext
    sudo systemctl status anythingllm-collector
    ```
    
3. **View logs**:
    
    * For server:
        
        ```plaintext
        sudo journalctl -u anythingllm-server -f
        ```
        
    * For collector:
        
        ```plaintext
        sudo journalctl -u anythingllm-collector -f
        ```
        

### Step 9: Accessing AnythingLLM

With both services running, you should now be able to access AnythingLLM on [`http://your-server-ip:3001`](http://your-server-ip:3001) or through your domain if you’ve set up DNS.
