Setup AnythingLLM Server on Bare Metal Ubuntu

Muhammad HassanMuhammad Hassan
3 min read

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

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:

     curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
     sudo apt-get install -y nodejs
    
  2. Install Yarn:

     npm install --global yarn
    

Verify the installations:

node -v
yarn -v

Step 2: Clone the AnythingLLM Repository

Next, clone the AnythingLLM repository to your server:

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:

     yarn setup
    
  2. Prepare the Environment: Copy the environment file template and adjust paths as needed:

     cp server/.env.example server/.env
    

    Set the STORAGE_DIR path inside server/.env:

     STORAGE_DIR="/your/absolute/path/to/server/storage"
    
  3. Edit Frontend Configuration: Update the frontend .env file for production:

     cd frontend
     nano .env
    

    Set VITE_API_BASE='/api' for proper API routing.

Step 4: Build the Frontend

  1. Build the frontend application:

     cd frontend
     yarn build
    
  2. Move the build files to the server public directory:

     cp -R frontend/dist server/public
    

Step 5: Set Up the Database

Prepare the SQLite database with the following commands:

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:

     cd server
     NODE_ENV=production node index.js &
    
  2. Start the Collector: In a new terminal or SSH session:

     cd collector
     NODE_ENV=production node index.js &
    

At this point, AnythingLLM should be running locally on 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:

     sudo nano /etc/systemd/system/anythingllm-server.service
    
  2. Add the following configuration:

     [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:

     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:

     sudo nano /etc/systemd/system/anythingllm-collector.service
    
  2. Add the following configuration:

     [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:

     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:

     sudo systemctl status anythingllm-server
    
  2. Check the status of the collector:

     sudo systemctl status anythingllm-collector
    
  3. View logs:

    • For server:

        sudo journalctl -u anythingllm-server -f
      
    • For collector:

        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 or through your domain if you’ve set up DNS.

0
Subscribe to my newsletter

Read articles from Muhammad Hassan directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Muhammad Hassan
Muhammad Hassan

Hey there! I'm currently working as an Associate DevOps Engineer, and I'm diving into popular DevOps tools like Azure Devops,Linux, Docker, Kubernetes,Terraform and Ansible. I'm also on the learning track with AWS certifications to amp up my cloud game. If you're into tech collaborations and exploring new horizons, let's connect!