I work with some projects that can be only used with specific versions of node/python and it’s not feasible to simply dockerize them. Every time I switch between these projects I’d need to reinstall different versions of node/python. That would be plain silly… BUT there’s a better way.
Node.js
For Node, there’s an npm package called n. And an external installer script called nvm
N package
- Install any version of node
- Run
npm install -g n
- Verify install:
n --help
Options I use the most:
- Install specific version:
n <version>
- e.g.:
n 15.5.1
- e.g.:
- Select version from installed:
n
- Install and use latest node version:
n latest
- Clean up all versions except the current:
n prune
In case it does not work without sudo
you can follow the advice in the docs:
To avoid requiring sudo for n and npm global installs, it is suggested you either install to your home directory using N_PREFIX, or take ownership of the system directories
Note: It’s not supported on windows.
NVM
Install following the guide
Install specific versions:
nvm install <version>
Select version from installed
nvm list
Install and use the latest version
nvm install latest
Clean up cache:
nvm cache clear
Uninstall a specific version:
nvm uninstall <version>
my favourite feature is that I can automatically load the selected version if an rc file is present:
node --version > .nvmrc && nvm use
Python
For Python, there’s a community made package manager solution called pyenv. It uses shell scripts and builds the selected python environment from source.
Options I use the most:
- Install specific python version:
pyenv install <version>
- e.g:
pyenv install 3.9.0
- e.g:
- Use specific python version only for the current folder structure:
pyenv local <version>
I hope it’ll help you as much as it helped me.
Note: It has a fork for windows.
Happy Coding!