---
title: "A Step-by-Step Guide to Installing Garnet"
url: https://www.geekcorelab.cn/en-US/post/hand-in-hand-teaching-you-how-to-install-garnet
updated: 2026-10-29T13:06:41.194558Z
author: "hhjmk"
summary: "Garnet 是微软用 C# 开发的 Redis 兼容缓存组件，需 .NET8 环境。文章介绍了在 Ubuntu 22.04 服务器上编译 Garnet 的步骤，包括下载源码、安装 .NET8 SDK、设置环境变量、构建和运行。编译成功后，Garnet 会在 3278 端口运行，支持 Redis 客户端连接。文章建议使用境外服务器避免网络问题，并提供了具体命令和操作截图说明。"
---

# A Step-by-Step Guide to Installing Garnet

What is Garnet
----------

Garnet is a Redis client-compatible caching component written in C# by Microsoft. You can connect to Garnet using the same connection method as a Redis client.

However, Garnet requires the .NET8 runtime to run. For convenience, you can consider building it into a Docker image.

Bare-metal deployment
----

First, it is recommended to use an overseas server for building to avoid the domestic network environment affecting the installation process. This tutorial uses a 雨云 server and Ubuntu 22.04 provided by 雨云 with no preinstalled apps. If you encounter any problems during installation, you can try a 1 元 one-day trial machine from 雨云; one day is enough to compile Garnet. Because the process involves compilation, here we directly try a machine with 8 cores and 16G memory.

![](/uploads/import-placeholder/343)

![](/uploads/import-placeholder/16)
First, you need to download the Garnet source code.

```
git clone https://github.com/microsoft/garnet.git
```

After that, you need to install a .NET8 SDK[1](#6f322df6-7f52-4ad5-84ff-62d7feb81007)

First, we download the installation script provided by Microsoft and grant it execute permission.

```
wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh
chmod +x ./dotnet-install.sh
```

Run the script to install the .NET8 SDK.

```
./dotnet-install.sh --channel 8.0
```

![](/uploads/import-placeholder/401)
Wait a moment until the following appears:

```
Installation finished successfully.
```

That means the installation was successful. Next, you need to set an environment variable.

```
export DOTNET_ROOT=$HOME/.dotnet
export PATH=$PATH:$DOTNET_ROOT:$DOTNET_ROOT/tools
```

After that, run the build command to start building.

```
cd garnet
dotnet restore
dotnet build -c Release
```

![](/uploads/import-placeholder/399)

![](/uploads/import-placeholder/168)
After a moment, you will see a build success message. These three lines mean:

- Build succeeded
- 0 warnings
- 0 errors

Next, let's try running it.

```
cd main/GarnetServer
dotnet run -c Release -f net8.0
```

![](/uploads/import-placeholder/101)
You can see that there is already a red gem. Try connecting to it. Note that Garnet uses port 3278. Those migrating directly from Redis should pay attention to changing the connection method, but there is no need to change the client; just use the Redis client to connect.

Create a Key:

![](/uploads/import-placeholder/194)
Success
