Skip to main content
The kratos upgrade command upgrades the Kratos CLI and all related protoc plugins to their latest versions.

Usage

kratos upgrade

Description

This command installs or updates all Kratos-related tools using go install. It ensures you have the latest versions of:
  • The Kratos CLI itself
  • All protoc plugins required for code generation
  • Standard Protocol Buffer and gRPC tools

What Gets Upgraded

The command upgrades the following packages:

Kratos CLI

github.com/go-kratos/kratos/cmd/kratos/v2The main Kratos command-line tool

protoc-gen-go-http

github.com/go-kratos/kratos/cmd/protoc-gen-go-http/v2Generates Kratos HTTP transport code from proto files

protoc-gen-go-errors

github.com/go-kratos/kratos/cmd/protoc-gen-go-errors/v2Generates error definitions and helper functions

protoc-gen-go

google.golang.org/protobuf/cmd/protoc-gen-goStandard Go protocol buffer compiler plugin

protoc-gen-go-grpc

google.golang.org/grpc/cmd/protoc-gen-go-grpcGenerates Go gRPC service code

protoc-gen-openapi

github.com/google/gnostic/cmd/protoc-gen-openapiGenerates OpenAPI specifications from proto files

When to Use

You should run kratos upgrade when:

Initial Setup

After installing Kratos for the first time to ensure all plugins are installed

New Release

When a new version of Kratos is released with new features or bug fixes

Missing Plugins

If kratos proto client fails due to missing protoc plugins

Compatibility Issues

When you need to ensure all tools are compatible with each other

Examples

Basic Upgrade

kratos upgrade
This installs all the latest versions of Kratos tools.

After Fresh Installation

# Install Kratos CLI
go install github.com/go-kratos/kratos/cmd/kratos/v2@latest

# Upgrade/install all plugins
kratos upgrade

Before Generating Proto Code

# Ensure all tools are up to date
kratos upgrade

# Now generate code
kratos proto client api

How It Works

The command executes go install for each package with the @latest tag:
go install github.com/go-kratos/kratos/cmd/kratos/v2@latest
go install github.com/go-kratos/kratos/cmd/protoc-gen-go-http/v2@latest
go install github.com/go-kratos/kratos/cmd/protoc-gen-go-errors/v2@latest
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
go install github.com/google/gnostic/cmd/protoc-gen-openapi@latest

Installation Location

All tools are installed to your $GOPATH/bin or $HOME/go/bin directory. Ensure this directory is in your system’s PATH:
# Add to ~/.bashrc or ~/.zshrc
export PATH="$PATH:$(go env GOPATH)/bin"

Verification

After upgrading, verify the installations:
# Check Kratos version
kratos --version

# Check protoc plugins
which protoc-gen-go
which protoc-gen-go-grpc
which protoc-gen-go-http
which protoc-gen-go-errors
which protoc-gen-openapi

Automatic Upgrade

The kratos proto client command automatically runs kratos upgrade if it detects missing protoc plugins. You can also run it manually to ensure everything is up to date.

Prerequisites

Before running kratos upgrade, ensure you have:
  • Go 1.19 or later installed
  • Internet connection to download packages
  • $GOPATH/bin in your system PATH

Troubleshooting

Ensure $GOPATH/bin is in your PATH:
export PATH="$PATH:$(go env GOPATH)/bin"
Or restart your terminal after adding it to your shell configuration.
If you encounter permission errors, ensure you have write access to $GOPATH/bin:
ls -la $(go env GOPATH)/bin
If downloads fail due to network issues:
# Configure Go proxy
go env -w GOPROXY=https://proxy.golang.org,direct

# Then retry
kratos upgrade
If you need specific versions instead of latest:
# Install specific version manually
go install github.com/go-kratos/kratos/cmd/kratos/[email protected]
It’s recommended to run kratos upgrade periodically to benefit from the latest features, performance improvements, and bug fixes.

Build docs developers (and LLMs) love