Local Source Code Start
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.
Environment Preparation
Python 3.12 is required. It is recommended to use pyenv for quick installation of the Python environment.
To install additional Python versions, use pyenv install.
To switch to the “3.12” Python environment, use the following command:
Start API service
-
Navigate to the
api
directory: -
Prepare the environment variable config file
-
Generate a random secret key and replace the value of SECRET_KEY in the .env file
-
Dependencies installation
uv is used to manage dependencies. Install the required dependencies with
uv
by 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:
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
pnpm
withnpm
.
Start Web Service
-
Enter the web directory
-
Dependencies installation
-
Prepare the environment variable config file
Create a file named
.env.local
in 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:
Access Dify
Access http://127.0.0.1:3000 via browsers to enjoy all the exciting features of Dify. Cheers ! 🍻
Was this page helpful?