My Direnv setup for Python & JS isolated development
AI Summary
Summary of Video Transcript
- Topic: Isolating project environments using direnv, pyenv, and nvm.
- Problem: Returning to an old project and finding it doesn’t work due to global dependency updates.
- Solution: Using
direnv
to set environment variables per directory.Detailed Instructions and Tips
- direnv:
- Creates a
.envrc
file in a project directory.- Automatically loads/unloads environment variables when entering/exiting the directory.
- Can set specific versions of tools and languages for a project.
- Example:
export HELLO=42
in.envrc
sets theHELLO
environment variable.- Security feature: Requires
direnv allow
to approve running new.envrc
content.- Installation: Packaged in most distributions, hook into shell with
eval "$(direnv hook bash)"
in.bashrc
.- pyenv:
- Manages Python versions.
- Install with
curl
orgit
.- Hook into shell similar to
direnv
.- Use
pyenv install
to install specific Python versions.- Specify Python version in
.envrc
withlayout pyenv <version>
.- nvm (Node Version Manager):
- Manages Node.js versions.
- Install with a
curl
script.- Hook into shell by adding a snippet to
.bashrc
or.profile
.- Use
nvm install <version>
to install specific Node versions.- Specify Node version in
.envrc
withuse node <version>
.- Requires an additional function in
.envrc
for proper setup.Conclusion
- Usage:
direnv
withpyenv
andnvm
allows for isolated Python and Node.js environments in project directories.- Benefit: Keeps the global system clean and prevents errors from outdated dependencies.
(Note: No URLs or CLI commands were provided in the text for extraction.)