Skip to Content
DocsDevelopmentGo / Rust / Java

Go / Rust / Java

This article covers how to set up Go, Rust, and Java development environments on Ubuntu 26.04.

Go Language

Install Go

Download the latest version from the official site:

# Check the current stable release at https://go.dev/dl/ first (e.g. go1.26.4), # then replace GO_VERSION below with the actual version number GO_VERSION=1.26.4 wget https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz # Remove old version and extract sudo rm -rf /usr/local/go sudo tar -C /usr/local -xzf go${GO_VERSION}.linux-amd64.tar.gz # Clean up the downloaded file rm go${GO_VERSION}.linux-amd64.tar.gz

Configure environment variables by adding the following to ~/.bashrc or ~/.zshrc:

export PATH=$PATH:/usr/local/go/bin export GOPATH=$HOME/go export PATH=$PATH:$GOPATH/bin

Apply the configuration and verify:

source ~/.bashrc go version

Configure Go Module Proxy

In mainland China, configuring a proxy is recommended to speed up module downloads:

go env -w GOPROXY=https://goproxy.cn,direct

Go Project Basics

# Initialize a module mkdir myproject && cd myproject go mod init github.com/username/myproject # Add a dependency go get github.com/gin-gonic/gin # Run the program go run main.go # Build go build -o myapp # Run tests go test ./... # Format code go fmt ./... # Install tools go install golang.org/x/tools/gopls@latest

Common Development Tools

# Language server (IDE support) go install golang.org/x/tools/gopls@latest # Linter go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest # Hot reload go install github.com/air-verse/air@latest

Rust Language

Install via rustup

rustup is the official Rust installer and version manager:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

During installation, select the default option (option 1). After installation, load the environment:

source "$HOME/.cargo/env"

Verify the installation:

rustc --version cargo --version

Configure China Mirror

Edit ~/.cargo/config.toml:

[source.crates-io] replace-with = 'ustc' [source.ustc] registry = "sparse+https://mirrors.ustc.edu.cn/crates.io-index/"

Or use the ByteDance mirror:

[source.crates-io] replace-with = 'rsproxy' [source.rsproxy] registry = "https://rsproxy.cn/crates.io-index" [registries.rsproxy] index = "https://rsproxy.cn/crates.io-index" [net] git-fetch-with-cli = true

Rust Basics

# Create a new project cargo new myproject cd myproject # Build and run cargo run # Build only cargo build # Build release version (optimized) cargo build --release # Run tests cargo test # Check code (no binary output, faster) cargo check # Format code cargo fmt # Lint cargo clippy # Add dependencies cargo add serde tokio

Manage Rust Toolchains

# Update Rust rustup update # Install nightly version rustup toolchain install nightly # Switch toolchains rustup default nightly rustup default stable # Set toolchain for a project rustup override set nightly # Install components rustup component add rust-analyzer rustup component add rust-src

Java (OpenJDK)

Install OpenJDK

Ubuntu 26.04’s repository provides multiple OpenJDK versions:

# Install the default OpenJDK 25 sudo apt install default-jdk -y # Or explicitly install OpenJDK 25 sudo apt install openjdk-25-jdk -y # If you only need to run Java programs sudo apt install default-jre -y

Verify the installation:

java --version javac --version

Manage Multiple Java Versions

# List installed Java versions sudo update-alternatives --list java # Switch the default Java version sudo update-alternatives --config java sudo update-alternatives --config javac

Configure JAVA_HOME

Add to ~/.bashrc:

export JAVA_HOME=/usr/lib/jvm/java-25-openjdk-amd64 export PATH=$JAVA_HOME/bin:$PATH
source ~/.bashrc echo $JAVA_HOME

Install Maven

Maven is the most widely used build tool for Java projects:

sudo apt install maven -y mvn --version

Basic usage:

# Create a project mvn archetype:generate -DgroupId=com.example -DartifactId=myapp -DarchetypeArtifactId=maven-archetype-quickstart # Compile mvn compile # Package mvn package # Run tests mvn test # Clean build artifacts mvn clean

Configure a China mirror by editing ~/.m2/settings.xml:

<settings> <mirrors> <mirror> <id>aliyun</id> <mirrorOf>central</mirrorOf> <name>Aliyun Maven Mirror</name> <url>https://maven.aliyun.com/repository/central</url> </mirror> </mirrors> </settings>

Install Gradle

# Install via SDKMAN (recommended) curl -s "https://get.sdkman.io" | bash source "$HOME/.sdkman/bin/sdkman-init.sh" sdk install gradle # Verify gradle --version

Manage JDKs with SDKMAN

SDKMAN makes it easy to manage multiple JDK distributions:

# List available JDKs sdk list java # Install a specific version sdk install java 21.0.5-tem # Switch versions sdk use java 21.0.5-tem sdk default java 21.0.5-tem

Each of these three languages has its strengths: Go is great for network services and cloud-native development, Rust excels at systems programming and high-performance scenarios, and Java is ideal for enterprise application development. Choose the right language based on your project requirements.

Last updated on