In modern software development, managing multiple versions of runtime environments is essential. Different projects often require different versions of Node.js or Python, and switching between them manually can be tedious and error-prone. This guide will walk you through using two powerful tools: nvm for Node.js and uv for Python.
Why Version Management Matters
Before diving into the tools, let's understand why version management is crucial:
- Project compatibility: Different projects may require specific runtime versions
- Testing: You need to test your code across multiple versions
- Isolation: Avoid conflicts between system-wide installations
- Easy upgrades: Switch versions without breaking existing projects
Part 1: Managing Node.js with nvm
nvm (Node Version Manager) is the most popular tool for managing Node.js versions. It's lightweight, easy to use, and works seamlessly across different projects.
Step 1: Install nvm
For macOS/Linux:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
For Windows:
Download and install nvm-windows
After installation, restart your terminal and verify:
nvm --version
Step 2: Install Node.js Versions
List available Node.js versions:
nvm ls-remote
Install a specific version:
nvm install 18.18.0
Install the latest LTS version:
nvm install --lts
Step 3: Switch Between Versions
Use a specific version:
nvm use 18.18.0
Check current version:
node --version
Step 4: Set Default Version
Set a default Node.js version for new terminal sessions:
nvm alias default 18.18.0
Step 5: Project-Specific Versions
Create a .nvmrc file in your project root:
18.18.0
Now, when you enter the project directory, simply run:
nvm use
nvm will automatically switch to the version specified in .nvmrc.
Part 2: Managing Python with uv
uv is a modern, blazingly fast Python package and project manager. It's significantly faster than traditional tools like pyenv and pip, and it handles both Python versions and virtual environments.
Step 1: Install uv
For macOS/Linux:
curl -LsSf https://astral.sh/uv/install.sh | sh
For Windows:
irm https://astral.sh/uv/install.ps1 | iex
Verify installation:
uv --version
Step 2: Install Python Versions
List available Python versions:
uv python list
Install a specific Python version:
uv python install 3.12.1
Install multiple versions:
uv python install 3.11.8 3.12.1
Step 3: Set Python Version for a Project
Navigate to your project directory and pin a Python version:
cd my-project
uv python pin 3.12.1
This creates a .python-version file that uv will automatically detect.
Step 4: Create Virtual Environments
Create a virtual environment with a specific Python version:
uv venv --python 3.12.1
Activate the virtual environment:
macOS/Linux:
source .venv/bin/activate
Windows:
.venv\Scripts\activate
Step 5: Install Packages
With uv, package installation is incredibly fast:
uv pip install requests numpy pandas
Install from requirements.txt:
uv pip install -r requirements.txt
Best Practices
For Node.js Projects:
-
Always use
.nvmrc: Document the required Node.js version in your repository -
Install project dependencies locally: Use
npm installoryarn installafter switching versions -
Avoid global packages: Use
npxto run packages without global installation
For Python Projects:
-
Use
.python-version: Let uv automatically detect the required Python version - Always use virtual environments: Isolate project dependencies
-
Generate requirements.txt: Keep track of dependencies with
uv pip freeze > requirements.txt
Quick Reference Commands
nvm Commands
nvm install <version> # Install a Node.js version
nvm use <version> # Switch to a version
nvm ls # List installed versions
nvm ls-remote # List available versions
nvm alias default <v> # Set default version
nvm uninstall <version> # Remove a version
uv Commands
uv python install <v> # Install Python version
uv python pin <version> # Pin version for project
uv python list # List available versions
uv venv # Create virtual environment
uv pip install <pkg> # Install package
uv pip freeze # List installed packages
Conclusion
Managing multiple runtime versions doesn't have to be complicated. With nvm and uv, you can:
- ✅ Switch between versions effortlessly
- ✅ Maintain project-specific configurations
- ✅ Avoid version conflicts
- ✅ Improve development workflow
Both tools are actively maintained, widely adopted, and will make your development experience much smoother. Give them a try in your next project!
Have you used nvm or uv in your projects? Share your experience in the comments below! 💬
Top comments (0)