Prerequisites
Setup Docker and Docker Compose
Before installing Dify, make sure your machine meets the following minimum system requirements:
- CPU >= 2 Core
- RAM >= 4 GiB
| Operating System | Software | Explanation |
|---|---|---|
| macOS 10.14 or later | Docker Desktop | Set the Docker virtual machine (VM) to use a minimum of 2 virtual CPUs (vCPUs) and 8 GB of initial memory. Otherwise, the installation may fail. For more information, please refer to the Docker Desktop installation guide for Mac. |
| Linux platforms | Docker 19.03 or later Docker Compose 1.25.1 or later | Please refer to the Docker installation guide and the Docker Compose installation guide for more information on how to install Docker and Docker Compose, respectively. |
| Windows with WSL 2 enabled | Docker Desktop | We recommend storing the source code and other data that is bound to Linux containers in the Linux file system rather than the Windows file system. For more information, please refer to the Docker Desktop installation guide for using the WSL 2 backend on Windows. |
If you need to use OpenAI TTS, FFmpeg must be installed on the system for it to function properly. For more details, refer to: Link.
Clone Dify Repository
Run the git command to clone the Dify repository.Start Middlewares with Docker Compose
A series of middlewares for storage (e.g. PostgreSQL / Redis / Weaviate (if not locally available)) and extended capabilities (e.g. Dify’s sandbox and plugin-daemon services) are required by Dify backend services. Start the middlewares with Docker Compose by running these commands:Setup Backend Services
The backend services include- API Service: serving API requests for Frontend service and API accessing
- Worker Service: serving the aync tasks for datasets processing, workspaces, cleaning-ups etc.
Start API Service
-
Navigate to the
apidirectory: -
Prepare the environment variable config file:
When the frontend and backend run on different subdomains, set
COOKIE_DOMAINto the site’s top-level domain (e.g.,example.com) in the.envfile.The frontend and backend must be under the same top-level domain to share authentication cookies. -
Generate a random secret key and replace the value of SECRET_KEY in the
.envfile: -
Install dependencies:
uv is used to manage dependencies.
Install the required dependencies with
uvby running:For macOS: install libmagic with
brew install libmagic. -
Perform the database migration:
Perform database migrations to the latest version:
-
Start the API service:
Expected output:
Start the Worker Service
To consume asynchronous tasks from the queue, such as dataset file import and dataset document updates, follow these steps to start the Worker service-
for macOS or Linux
If you are using a Windows system to start the Worker service, please use the following command instead:
-
for Windows
Expected output:
Start the Beat Service
Additionally, if you want to debug the celery scheduled tasks or run the Schedule Trigger node, you can run the following command in another terminal to start the beat service:Setup Web Service
Start the web service is built for frontend pages .Environment Preparation
To start the web frontend service, Node.js v22 (LTS) and PNPM v10 are requied.- Install NodeJS Please visit https://nodejs.org/en/download and choose the installation package for your respective operating system that is v18.x or higher. LTS version is recommanded for common usages.
-
Install PNPM
Follow the the installation guidance to install PNPM. Or just run this command to install
pnpmwithnpm.
Start Web Service
-
Enter the web directory:
-
Install dependencies:
-
Prepare the environment variable configuration file
Create a file named.env.localin the current directory and copy the contents from.env.example. Modify the values of these environment variables according to your requirements: -
Build the web service:
-
Start the web service:
Expected output: