Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
June 14, 2022 10:23 pm GMT

Setup asdf & direnv

Environment setup

ASDF Version Manager

asdf is a tool version manager. All tool version definitions are contained within one file (.tool-versions) which you can check in to your project's Git repository to share with your team, ensuring everyone is using the exact same versions of tools.

Reference: https://asdf-vm.com/guide/introduction.html

Install asdf

  • Make sure you have curl and git installed.
  • Download asdf with

    git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.10.0
  • If you are using bash, add the following to your ~/.bashrc file:

    . $HOME/.asdf/asdf.sh# configure completions. $HOME/.asdf/completions/asdf.bash
  • If you are using zsh, add the following to your ~/.zshrc file:

    . $HOME/.asdf/asdf.sh# if using oh-my-zsh, add `asdf` to your plugins list# for example: plugins=(... asdf ...)# if you are not using oh-my-zsh, add the following to your `.zshrc` file:# append completions to fpathfpath=(${ASDF_DIR}/completions $fpath)# initialise completions with ZSH's compinitautoload -Uz compinit && compinit

Install plugins

After installing asdf, add all the plugins found in the .tool-versions file. This depends on the tools defined in your .tool-versions file depending on the repository.

# Add all the plugins to asdf.cat .tool-versions | awk '{print $1}' | xargs -I _ asdf plugin add _# Install all tools according to .tool-versions.asdf install

Example

If your project's .tool-versions file contains the following:

ruby 2.6.3python 3.10.4nodejs 16.0.0

Then you can install all the tools with their specified versions by running asdf install.

Global tool versions

Optionally, you can add the following .tool-versions file to your home directory:

direnv 2.31.0nodejs 16.13.2pnpm 7.1.5java adoptopenjdk-8.0.272+10minikube 1.25.1helm 3.6.3helmfile 0.139.9kubectl 1.23.3kubespy 0.6.0kubectx 0.9.4jq 1.6golang 1.15.15poetry 1.1.13

!!! Note
Make sure you stay up to date with the latest or stable versions of tools.

Refer to official asdf documentation for more information.

Direnv

direnv is an extension for your shell. It augments existing shells with a new feature that can load and unload environment variables depending on the current directory.

Setup any project with direnv by creating a .envrc file that looks like the following:

#!/usr/bin/env bashexport CR_PAT=<YOUR_GITHUB_PAT_WITH_REPO_READ_AND_WRITE>export NODE_AUTH_TOKEN=$CR_PATexport DEBUG="*"cat <<EOF >.envVITE_BASE_URL=${VITE_BASE_URL}NODE_AUTH_TOKEN=${CR_PAT}EOF

Hook asdf with direnv

Setup

  • Install asdf-plugin for direnv using the following:

    asdf plugin-add direnv
  • Setup shell

    # change --shell flag based on your current shell (bash, zsh, fish, etc.)asdf direnv setup --shell zsh --version latest
  • Once direnv is hooked up, you can run the following command on the root directory of your project to update your environment given that you have a .envrc file in your project root.

    asdf direnv local

Creating temporary environments

You can create a temporary environment without editing .envrc or .tool-versions

# Enter a new shell having python and nodeasdf direnv shell python 3.8.10 nodejs 14.18.2# Just execute a npx command under some node versionasdf direnv shell nodejs 14.18.2 -- npx create-react-app

References:


Original Link: https://dev.to/deepanchal/setup-asdf-direnv-5afo

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To