Advanced Installation Commands
Install Node.js from Source
For developers needing a specific setup or patch:
nvm install -s <node_version>
Reinstall Packages When Installing a New Version
Easily transfer global packages to the newly installed version:
nvm install <node_version> --reinstall-packages-from=current
Install Multiple Versions Simultaneously
Batch install several versions at once:
nvm install <node_version_1> <node_version_2> <node_version_3>
Efficient Node Version Switching
Switching with Environment Variables
Automatically switch Node.js versions based on your project’s configuration:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
nvm use
By adding a .nvmrc file in your project directory containing the desired Node.js version, NVM will switch versions automatically when you navigate to the project.
Persistent Node.js Version Across Terminals
Ensure consistency across different terminal sessions:
nvm alias default <node_version>
Enhanced Listing and Filtering
List All Installed Versions with Detailed Info
See comprehensive details about installed Node.js versions:
nvm ls
Filter Installed Versions
Quickly locate specific versions:
nvm ls | grep <filter>
List All Available Versions and Highlight Specifics
For in-depth searching:
nvm ls-remote --lts # Lists all LTS versions
nvm ls-remote | grep "v14" # List all v14.x versions
Managing Global Packages
List and Migrate Global Packages
Identify and migrate global packages to another Node.js version:
nvm list global # Lists globally installed packages for the current version
nvm reinstall-packages <node_version> # Reinstall global packages from a specific version
Removing Outdated Global Packages
Clean up outdated packages:
npm uninstall -g <package_name>
Leveraging Aliases
Creating Custom Aliases
Define custom aliases for frequent version switches:
nvm alias myproject <node_version>
Updating and Deleting Aliases
Modify or remove aliases as your projects evolve:
nvm alias <alias_name> <new_node_version>
nvm unalias <alias_name>
Path and Version Verification
Locate Executables
Quickly find where specific versions are installed:
nvm which <node_version>
Verify Multiple Versions Simultaneously
Check installed versions of Node, NPM, and NVM:
node -v && npm -v && nvm -v
Cleaning Up
Removing Old or Unused Versions
Free up space by uninstalling unnecessary versions:
nvm uninstall <node_version>
Automate Version Removal
Automate cleanup based on a condition or date:
nvm ls | grep -E "v[0-9]+\.[0-9]+\.[0-9]+" | xargs -I {} nvm uninstall {}
Troubleshooting
Resolving Common Issues
Identify and fix common NVM problems:
nvm debug
Resetting NVM Environment
If things go awry, reset your NVM setup:
rm -rf ~/.nvm
git clone https://github.com/nvm-sh/nvm.git ~/.nvm
cd ~/.nvm
git checkout git describe --abbrev=0 --tags
. nvm.sh
By mastering these advanced NVM commands, you'll enhance your Node.js development experience, ensuring optimal performance and flexibility. Dive deeper, experiment, and watch your productivity soar!
Top comments (0)