Build LocalAI
Build
LocalAI can be built as a container image or as a single, portable binary. Note that some model architectures might require Python libraries, which are not included in the binary.
LocalAI’s extensible architecture allows you to add your own backends, which can be written in any language, and as such the container images contains also the Python dependencies to run all the available backends (for example, in order to run backends like Diffusers that allows to generate images and videos from text).
This section contains instructions on how to build LocalAI from source.
Build LocalAI locally
Requirements
In order to build LocalAI locally, you need the following requirements:
- Golang >= 1.21
- GCC
- GRPC
To install the dependencies follow the instructions below:
To build pure-Go backend hosts that load Metal libraries, use Go 1.27 or later on macOS 13 or later.
Go 1.27 records macOS SDK 26.2 in internally linked executables, which enables modern Metal APIs in these hosts.
Rebuild the affected backend after upgrading Go. Rebuilding only local-ai does not update installed backend executables.
Install xcode from the App Store
After you have golang installed and working, you can install the required binaries for compiling the golang protobuf components via the following commands
After you have golang installed and working, you can install the required binaries for compiling the golang protobuf components via the following commands
Build
To build LocalAI with make:
git clone https://github.com/go-skynet/LocalAI
cd LocalAI
make buildThis should produce the binary local-ai
Container image
Requirements:
- Docker or podman, or a container engine
In order to build the LocalAI container image locally you can use docker, for example:
docker build -t localai .
docker run localaiChoosing the ROCm release for hipblas builds
For BUILD_TYPE=hipblas the ROCm release comes from the base image, and the
build installs the ROCm BLAS development packages from the base image’s apt
repository. Both are build arguments of the main Dockerfile,
backend/Dockerfile.python, backend/Dockerfile.golang and the builders that
run .docker/install-base-deps.sh (backend/Dockerfile.base-grpc-builder,
backend/Dockerfile.llama-cpp and its siblings):
| Build argument | Default | Meaning |
|---|---|---|
BASE_IMAGE | rocm/dev-ubuntu-24.04:10.1.0-full in CI | Image that provides ROCm and its apt repository |
ROCM_PACKAGES | amdrocm-blas-dev10.1 | Packages installed when BUILD_TYPE=hipblas and SKIP_DRIVERS=false |
The defaults are for ROCm 10.1, which ships from AMD’s repository
stable.repo.amd.com/rocm/core. There, the hipBLAS, rocBLAS and hipBLASLt
headers are in one package, amdrocm-blas-dev<version>. The 10.1.0-full
image already contains them, so the install step changes nothing there; it
matters for a slimmer base that only has AMD’s apt source configured.
Two Dockerfiles use a different default:
backend/Dockerfile.audio-cppalso needs the hipCUB headers and installsamdrocm-blas-dev10.1 amdrocm-ccl-dev10.1.backend/Dockerfile.pythonstays on ROCm 7.2.1 (rocm/dev-ubuntu-24.04:7.2.1withhipblas-dev hipblaslt-dev rocblas-dev). The Python backends get their GPU code from the ROCm PyTorch wheels inrequirements-hipblas.txt, and PyTorch does not publish ROCm 10.1 wheels yet.
To build against ROCm 7.x, set both arguments together. ROCm 7.x uses the older package names:
docker build \
--build-arg BUILD_TYPE=hipblas \
--build-arg BASE_IMAGE=rocm/dev-ubuntu-24.04:7.2.1 \
--build-arg ROCM_PACKAGES="hipblas-dev hipblaslt-dev rocblas-dev" \
-t localai:hipblas-rocm7 .The make docker and make docker-build-<backend> targets forward
BASE_IMAGE and, when set, ROCM_PACKAGES:
make BUILD_TYPE=hipblas BASE_IMAGE=rocm/dev-ubuntu-24.04:7.2.1 \
ROCM_PACKAGES="hipblas-dev hipblaslt-dev rocblas-dev" docker-build-whisperROCm 7.x and 10.x lay out /opt/rocm differently: 10.x installs into
/opt/rocm/core-<version>/ and has no /opt/rocm/llvm. The builds run
.docker/rocm-compat-links.sh, which adds /opt/rocm/llvm (the backend
Makefiles compile with /opt/rocm/llvm/bin/clang++) and links
/usr/lib/libomp.so on both layouts.
An empty ROCM_PACKAGES installs nothing, for a base image that already ships
the ROCm development packages. Unlike SKIP_DRIVERS=true, the image is still
marked as an AMD image, so meta backends resolve to their ROCm variants.
CI builds the ROCm 10.1 defaults, and ROCm 7.2.1 for the Python backends.
Example: Build on mac
Building on Mac (M1, M2 or M3) works, but you may need to install some prerequisites using brew.
The below has been tested by one mac user and found to work. Note that this doesn’t use Docker to run the server:
Install xcode from the Apps Store (needed for metalkit)
brew install abseil cmake go grpc protobuf wget protoc-gen-go protoc-gen-go-grpc
git clone https://github.com/go-skynet/LocalAI.git
cd LocalAI
make build
wget https://huggingface.co/TheBloke/phi-2-GGUF/resolve/main/phi-2.Q2_K.gguf -O models/phi-2.Q2_K
cp -rf prompt-templates/ggml-gpt4all-j.tmpl models/phi-2.Q2_K.tmpl
./local-ai backends install llama-cpp
./local-ai --models-path=./models/ --debug=true
curl http://localhost:8080/v1/models
curl http://localhost:8080/v1/chat/completions -H "Content-Type: application/json" -d '{
"model": "phi-2.Q2_K",
"messages": [{"role": "user", "content": "How are you?"}],
"temperature": 0.9
}'Troubleshooting mac
If you encounter errors regarding a missing utility metal, install
Xcodefrom the App Store.After the installation of Xcode, if you receive a xcrun error
'xcrun: error: unable to find utility "metal", not a developer tool or in PATH'. You might have installed the Xcode command line tools before installing Xcode, the former one is pointing to an incomplete SDK.
xcode-select --print-path
sudo xcode-select --switch /Applications/Xcode.app/Contents/DeveloperIf completions are slow, ensure that
gpu-layersin your model yaml matches the number of layers from the model in use (or simply use a high number such as 256).If you get a compile error:
error: only virtual member functions can be marked 'final', reinstall all the necessary brew packages, clean the build, and try again.
brew reinstall go grpc protobuf wget
make clean
make buildBuild backends
LocalAI have several backends available for installation in the backend gallery. The backends can be also built by source. As backends might vary from language and dependencies that they require, the documentation will provide generic guidance for few of the backends, which can be applied with some slight modifications also to the others.
Manually
Typically each backend include a Makefile which allow to package the backend.
In the LocalAI repository, for instance you can build a backend by doing:
git clone https://github.com/go-skynet/LocalAI.git
make -C LocalAI/backend/python/vllmWith Docker
Building with docker is simpler as abstracts away all the requirement, and focuses on building the final OCI images that are available in the gallery. This allows for instance also to build locally a backend and install it with LocalAI. You can refer to Backends for general guidance on how to install and develop backends.
In the LocalAI repository, you can build a backend by doing:
git clone https://github.com/go-skynet/LocalAI.git
make docker-build-<backend-name>Note that make is only by convenience, in reality it just runs a simple docker command as:
Note:
- BUILD_TYPE can be either:
cublas,hipblas,sycl_f16,sycl_f32,metal. - BASE_IMAGE is tested on
ubuntu:24.04(and defaults to it) andintel/oneapi-basekit:2025.3.2-0-devel-ubuntu24.04for intel/sycl