DNVM (Docker Node Version Manager) is a Zsh plugin that allows you to easily switch between Node.js versions using Docker containers. It's designed to be compatible with Antígeno and provides a familiar interface similar to nvm.
- 🚀 Docker-based: Each Node.js version runs in an isolated Docker container
- ⚡ Session-based: Version changes only affect the current terminal session
- 🔄 Auto-detection: Automatically switches versions based on
.nvmrc
files - 📦 Global packages: Seamlessly manages global packages with wrapper generation
- 🎯 Antígeno compatible: Easy to install and manage with Antígeno
- 🔧 Environment variables: Passes all shell environment variables to containers
- Docker: Must be installed and running
- Zsh: Compatible Zsh shell
- Antígeno: Optional but recommended for easy installation
- Clone this repository:
git clone <your-repo-url> ~/.dnvm
cd ~/.dnvm
- Add to your
.zshrc
:
source ~/.dnvm/dnvm.plugin.zsh
- Restart your terminal or source your
.zshrc
:
source ~/.zshrc
Add this line to your .zshrc
:
antigen bundle <your-github-repo>
Then run:
antigen update
dnvm use 18.16.0
dnvm use 20
dnvm use v16.15.0 # 'v' prefix is automatically handled
dnvm global 20
dnvm global 18.16.0
dnvm versions
dnvm current
Create a .nvmrc
file in your project:
echo "20.0.0" > .nvmrc
DNVM will automatically switch to this version when you cd
into the directory.
On first installation, DNVM will:
- Pull a default LTS Node.js Docker image
- Install default global packages (yarn, pnpm, npx)
- Set up necessary directories and configurations
npm install -g create-react-app
yarn global add eslint
DNVM will automatically:
- Install the package in the current Node.js version's Docker container
- Generate a wrapper script for the package
- Add the wrapper to your PATH for the current session
After installation, you can use the global packages directly:
create-react-app my-app
eslint src/
Similar to the original NVM, DNVM now supports automatic installation of default global packages when switching to a Node.js version.
Create a default packages file:
# Create/edit default packages list
vim ~/.config/dnvm/default-packages
# Example content:
yarn
pm2
npm-check-updates
# typescript
nodemon
How it works:
- When you run
dnvm use <version>
, DNVM automatically checks~/.config/dnvm/default-packages
- Packages listed in this file (one per line) are installed globally if not already installed for that Node version
- Lines starting with
#
are treated as comments and ignored - Wrapper scripts are automatically generated for each installed package
Example workflow:
# First time using Node 20
dnvm use 20
# Output:
# Checking default packages for Node.js 20...
# Installing yarn globally for Node.js 20...
# ✓ yarn installed successfully
# Installing pm2 globally for Node.js 20...
# ✓ pm2 installed successfully
# Installing npm-check-updates globally for Node.js 20...
# ✓ npm-check-updates installed successfully
# Default package installation completed.
Benefits:
- ⚡ Fast setup of new Node versions with your favorite tools
- 🔄 Consistent development environment across versions
- 📦 Automatic wrapper generation for easy package access
- 💾 Version-specific package management
DNVM automatically manages npm configuration:
- Copies your
~/.npmrc
to each Node.js version - Creates default
.npmrc
if none exists - Supports custom registries, cache settings, and authentication
Example configuration:
# ~/.npmrc dosyası bu örnekte ~/.config/dnvm/npmrc/.npmrc-20.0.0 konumuna kopyalanır
registry=https://registry.npmjs.org/
save-exact=true
progress=false
cache-max=86400
fund=false
audit=false
# DNVM-specific Docker paths
prefix=/home/node/.local
cache=/home/node/.npm-cache
# Authentication
//registry.npmjs.org/:_authToken=your_token_here
Konfigürasyon Dosyası:
# DNVM her Node versiyonu için ayrı .npmrc dosyası oluşturur:
~/.config/dnvm/npmrc/.npmrc-18 # Node 18 konfigürasyonu
~/.config/dnvm/npmrc/.npmrc-20 # Node 20 konfigürasyonu
~/.config/dnvm/npmrc/.npmrc-16 # Node 16 konfigürasyonu
All your shell's environment variables are automatically passed to the Docker containers:
MY_VAR=test node app.js
export API_KEY=secret123
node server.js # API_KEY will be available in the container
DNVM uses the XDG Base Directory specification:
# Data directory (Docker volumes and binaries)
$XDG_DATA_HOME/dnvm/
├── bin/
│ ├── dnvm-node-exec # Docker runner
│ └── {version}/ # Version-specific wrappers
│ ├── eslint
│ └── create-react-app
├── volumes/{version}/ # Docker volumes for Node.js data
└── home/node/...
# Config directory
$XDG_CONFIG_HOME/dnvm/
├── version # Global default version
├── default-packages # List of global packages to install
Each Node.js version runs in an isolated Docker container:
- Working directory:
/app
(mounted from your current directory) - Node data volume:
/home/node
(persistent storage for packages) - User permissions: Current user ID and group ID
- Environment: All your shell environment variables
Global packages are automatically wrapped:
# Generated wrapper example: bin/20.0.0/eslint
#!/usr/bin/env zsh
exec dnvm-node-exec 20.0.0 eslint "$@"
dnvm use {version}
changes the Node.js version for the current terminal session only- New terminal windows will use the global default version
- Directory changes automatically trigger .nvmrc detection
- Global packages are installed in Docker containers (not on host system)
- Wrapper scripts provide transparent access to these packages
- Packages are automatically re-installed when switching to new versions
# Check if Docker is running
docker info
# Pull a specific Node version manually
docker pull node:18.16.0
# Check what versions are available in Docker Hub
curl -s https://registry.hub.docker.com/v1/repositories/library/node/tags | jq -r '.[] | .name' | head -10
# Ensure your user has Docker permissions
sudo usermod -aG docker $USER
# Log out and back in for changes to take effect
# Remove all DNVM data and start fresh
rm -rf "$XDG_DATA_HOME/dnvm"
rm -rf "$XDG_CONFIG_HOME/dnvm"
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly with different Node versions
- Submit a pull request
MIT License - see LICENSE file for details
Happy coding with DNVM! 🎉