Skip to content

Instantly share code, notes, and snippets.

@leodutra
Last active January 15, 2024 16:54
Show Gist options
  • Save leodutra/20b45c1b0eddd56450f3455b4487fe26 to your computer and use it in GitHub Desktop.
Save leodutra/20b45c1b0eddd56450f3455b4487fe26 to your computer and use it in GitHub Desktop.
Rust + Ubuntu Dev Env 2023 + utillities / tools / cli / plugins / cargo / components / sub commands

Install steps

# update the system
sudo apt update && sudo apt upgrade -y

# install minimal dev stuff
sudo apt install -y \
	build-essential \
	ca-certificates \
	cmake \
	curl \
	git \
	gnupg \
	libssl-dev \
	pkg-config \
	python-is-python3 python3-pip \
	wget \
	zsh

# enter zsh
zsh

### Oh My Zsh #############################################
# install oh-my-zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

# install zsh-completions
git clone https://github.com/zsh-users/zsh-completions ${ZSH_CUSTOM:-${ZSH:-~/.oh-my-zsh}/custom}/plugins/zsh-completions

# install zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

# zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

# exa-zsh
git clone https://github.com/MohamedElashri/exa-zsh ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/exa-zsh

# exa-bat
git clone https://github.com/fdellwing/zsh-bat.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-bat

# zsh-cargo-completion
git clone https://github.com/MenkeTechnologies/zsh-cargo-completion.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-cargo-completion

# install Powerlevel9k theme for Oh My Zsh
git clone https://github.com/bhilburn/powerlevel9k.git ~/.oh-my-zsh/custom/themes/powerlevel9k

# install Powerlevel9k fonts
sudo apt-get install fonts-powerline -y

# install starship
curl -sS https://starship.rs/install.sh | sh


### Node.js ###############################################
# install FNM for Zsh
SHELL=/usr/bin/zsh curl -fsSL https://fnm.vercel.app/install | zsh
source .zshrc
fnm install --lts
fnm default "lts/*"
node -v

# install Nodemon, PM2, ESLint, Pug, TypeScript
npm i -g nodemon pm2 eslint pug typescript

### Docker ##############################################################
# remove old packages
for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt-get remove $pkg; done

# add Docker's official GPG key
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

# add the repository to Apt sources:
echo \
  "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

# create docker group
sudo groupadd docker
# add user to the docker group
sudo usermod -aG docker $USER
# activate groups
newgrp docker

# configure Docker to start on boot with systemd
sudo systemctl enable docker.service
sudo systemctl enable containerd.service


### Rust & Rust-based ###################################################
# install rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source "$HOME/.cargo/env"
rustup update stable
rustup component add rls
rustup component add rust-analysis
rustup component add rust-docs
rustup component add rust-src
rustup component add rustfmt
rustup component add clippy

# install nightly rust
rustup toolchain install nightly

# install sccache for rustc
cargo install -f sccache
echo 'export RUSTC_WRAPPER=sccache' >> ~/.zshrc 
source .zshrc

# install interesting cargo tools
cargo +stable install -f --locked cargo-asm cargo-benchcmp cargo-cache cargo-deadlinks cargo-deb cargo-diet cargo-edit cargo-expand cargo-tomlfmt cargo-fuzz cargo-graph cargo-show-asm cargo-update cargo-watch

# install interesting rust cli tools
cargo +stable install -f --locked broot git-delta gitui kmon spotify-tui
cargo +stable install \
  --git https://github.com/cloudhead/rx \
  --tag v0.5.2

# install interesting rust cli utilities
sudo apt install -y nnn
cargo +stable install -f --locked bat bottom drill dtool dua du-dust exa fd-find hyperfine licensor monolith navi oha onefetch pastel procs ripgrep sd tealdeer tickrs tokei tre-command zoxide

# install terminal workspace (multi.)
cargo install -f --locked zellij

# install alacritty
sudo apt install -y cmake pkg-config libfreetype6-dev libfontconfig1-dev libxcb-xfixes0-dev libxkbcommon-dev python3
git clone https://github.com/alacritty/alacritty.git ~/workspaces/alacritty
cargo build --release
sudo cp target/release/alacritty /usr/local/bin
sudo cp extra/logo/alacritty-term.svg /usr/share/pixmaps/Alacritty.svg
sudo desktop-file-install extra/linux/Alacritty.desktop
sudo update-desktop-database

# alacritty zsh completions
mkdir -p ${ZDOTDIR:-~}/.zsh_functions
echo 'fpath+=${ZDOTDIR:-~}/.zsh_functions' >> ${ZDOTDIR:-~}/.zshrc
cp extra/completions/_alacritty ${ZDOTDIR:-~}/.zsh_functions/_alacritty

sudo update-alternatives --install /usr/bin/x-terminal-emulator x-terminal-emulator /usr/local/bin/alacritty 50
sudo update-alternatives --config x-terminal-emulator

# install helix editor
sudo add-apt-repository ppa:maveonair/helix-editor
sudo apt update
sudo apt install -y helix
  
# install frum (ruby manager)
cargo install -f --locked frum

# clean cargo
cargo cache -a
cargo install-update -a

# install neofetch
sudo apt install -y neofetch

ZSH Config (.zshrc)

# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH

# Path to your oh-my-zsh installation.
export ZSH="$HOME/.oh-my-zsh"

# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
# ZSH_THEME="robbyrussell"
ZSH_THEME="powerlevel9k/powerlevel9k"
POWERLEVEL9K_MODE='nerdfont-complete'

# VSCode specific styling (+usage):
# "terminal.integrated.env.linux": {
#     "ZSHRC_VSCODE_MODE": "true"
# }
if [ "$ZSHRC_VSCODE_MODE" = "true" ]; then
    POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(os_icon dir vcs)
else
    POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context dir vcs)
fi

# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in $ZSH/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )

# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"

# Uncomment the following line to use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"

# Uncomment one of the following lines to change the auto-update behavior
# zstyle ':omz:update' mode disabled  # disable automatic updates
# zstyle ':omz:update' mode auto      # update automatically without asking
# zstyle ':omz:update' mode reminder  # just remind me to update when it's time

# Uncomment the following line to change how often to auto-update (in days).
# zstyle ':omz:update' frequency 13

# Uncomment the following line if pasting URLs and other text is messed up.
# DISABLE_MAGIC_FUNCTIONS="true"

# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"

# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"

# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"

# Uncomment the following line to display red dots whilst waiting for completion.
# You can also set it to another string to have that shown instead of the default red dots.
# e.g. COMPLETION_WAITING_DOTS="%F{yellow}waiting...%f"
# Caution: this setting can cause issues with multiline prompts in zsh < 5.7.1 (see #5765)
# COMPLETION_WAITING_DOTS="true"

# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"

# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
# HIST_STAMPS="mm/dd/yyyy"

# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder

# Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(
	aws
	colorize
	command-not-found
	docker
	docker-compose
	exa-zsh
	fd
	fnm
	git
	git-lfs
	history
	man
	node
	npm
	postgres
	react-native
	ripgrep
	rust
	sudo
	systemd
	terraform
	ubuntu
	ufw
	vscode
	wakeonlan
	web-search
	yarn
	# zoxide
	# zsh-autocomplete
	zsh-autosuggestions
	zsh-bat
	zsh-cargo-completion
	zsh-completions
	zsh-syntax-highlighting
)

source $ZSH/oh-my-zsh.sh

# User configuration

# export MANPATH="/usr/local/man:$MANPATH"

# You may need to manually set your language environment
# export LANG=en_US.UTF-8

# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
#   export EDITOR='vim'
# else
#   export EDITOR='mvim'
# fi

# Compilation flags
# export ARCHFLAGS="-arch x86_64"

# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"

# starship
eval "$(starship init zsh)"

# fnm
export PATH="/home/leo/.local/share/fnm:$PATH"
eval "`fnm env`"

# use rust-src
export RUST_SRC_PATH=$(rustc --print sysroot)/lib/rustlib/src/rust/library

# sccache for faster cargo builds
export RUSTC_WRAPPER=sccache

# zoxide
eval "$(zoxide init zsh)"

# tools & utils aliases
alias ls='exa'
alias x='exa'
alias find='fd'
alias grep='rg'
alias du='dust'
alias cat='bat'
alias time='hyperfine'
alias cloc='tokei'
alias ps='procs'
alias sed='sd'
alias top='btm'
alias htop='btm'


neofetch
fpath+=${ZDOTDIR:-~}/.zsh_functions

Third-Party Cargo Extras

Reference: https://github-wiki-see.page/m/rust-lang/cargo/wiki/Third-party-cargo-subcommands

cargo-audit - Audit Cargo.lock for crates with security vulnerabilities
cargo-asm, cargo-llvm-ir / cargo show-asm - Shows generates assembly or LLVM IR of Rust code
cargo-benchcmp - Compare output of cargo bench output, both runs over time and same benchmarks in multiple modules (e.g. for comparing multiple implementations)
cargo-bitbake - Generate Yocto's bitbake recipes from your Cargo.toml
cargo-bloat - Find out what takes most of the space in your executable.
cargo-cache - Helps you manage the cargo cache (~/.cargo), print sizes and clear directories
cargo-check - This is a wrapper around cargo rustc -- -Zno-trans. It can be helpful for running a faster compile if you only need correctness checks.
cargo-cook - Cooks your crate (packaging & deploying).
clippy - Lint your project using Clippy.
cargo-cln - Alternative to cargo-clean, allows running arbitrary commands in addition to wiping out target/ directory.
cargo-clone - Fetch source code of a crate
cargo-config - Print info about the current crate.
cargo-count - counts lines of code in cargo projects, including giving naive unsafe statistics
cargo-deadlinks - Check your cargo doc documentation for broken links
cargo-deb - Generates & builds Debian packages from cargo projects.
cargo-deny - Lint your dependencies
cargo-deps - Create dependency diagrams for your Rust projects.
cargo-diet - Make your crate lean by computing size-optimal include directives for Cargo manifests.
cargo-do - Run multiple cargo subcommands in sequence (e.g., cargo do clean, build)
dors - Task runner for cargo. Deploy, load, or run other scripts from your cargo project
cargo-edit - A utility for adding (cargo-add), removing (cargo-rm), and upgrading (cargo-upgrade) cargo dependencies from the command line.
cargo-expand - Print the result of macro expansion and #[derive] expansion.
rustfmt - Format Rust code according to style guidelines.
cargo-free - Check whether a crate name is available on crates.io.
cargo-funnel - Sorts and formats your Cargo.toml
cargo-fuzz - Command-line wrapper for using libFuzzer
cargo-generate - Create a new Rust project by leveraging a pre-existing git repository as a template.
cargo-grammarly - Use the grammarly service for checking English grammar in your crate's documentation.
cargo-graph - Build GraphViz DOT files of dependency graphs. Unmaintained, consider using cargo-deps.
cargo-info - Get crate information and details from crates.io
cargo-license - List licensing info for the project's dependencies.
cargo-linked - List Linked packages for a rust binary.
cargo-lipo - Automatically create universal libraries for iOS.
cargo-lock - List packages, show dependency trees, and translate formats for Cargo.lock files.
cargo-make - Rust task runner and build tool.
cargo-modules - List a project's modules in a tree-like format.
cargo-multi - Run a cargo command on multiple crates.
cargo-next - Query or set the version of a crate.
cargo-open - Quickly open your crate in your editor.
cargo-outdated - A cargo subcommand for displaying when Rust dependencies are out of date
cargo-patch - Cargo Subcommand for patching dependencies using patch files.
cargo-pkgbuild - Generate an Arch PKGBUILD for your crate.
cargo-profiler - A cargo subcommand to profile your applications.
cargo-release - Standardizes the release process of a cargo project.
cargo-repro - Build and verify byte-for-byte reproducible Rust packages using a Cargo-based workflow (WIP).
cargo-rpm - Build RPM releases of Rust projects using cargo.
cargo-sandbox - Perform Cargo builds inside of a sandboxed environment (WIP).
cargo-script - designed to let people quickly and easily run Rust "scripts" which can make use of Cargo's package ecosystem.
cargo-sort-ck - Checks that your Cargo.toml dependencies are sorted alphabetically.
cargo-supply-chain - Gather author, contributor and publisher data on crates in your dependency graph.
cargo-tarpaulin - Code coverage tool for your Rust projects
cargo-tomlfmt - Formatting Cargo.toml
cargo-tree - List a project's dependencies in a tree-like format. Also supports an "inverted" mode to help determine why a specific crate is being pulled in.
cargo-update - Check for cargo installed executables' newer versions and update as needed.
cargo-urlcrate - Adds URLs of installing/downloading crates to Cargo output
cargo-valgrind - Runs a binary, example, bench, ... inside valgrind to check for memory leaks. Helpful in FFI contexts.
cargo-vendor - Vendors all crates.io dependencies into a local directory using Cargo's support for source replacement
cargo-watch - Watch your repo for changes and build automatically.
cargo-whereis - Locate a particular crate within a workspace.
cargo-with - A cargo-subcommand making it easy to run the build artifacts produced by cargo run or cargo build through other tools such as gdb, strace, valgrind, rr, etc.
cargo-wix - Builds a Windows installer (msi) using the Wix Toolset based on the contents of a package's manifest (Cargo.toml)
cargo-x - A very simple third-party cargo subcommand to execute a custom command.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment