How do I find the currently activated version with nvm?

天涯浪子 提交于 2020-03-05 06:00:32

问题


I use nvm and want to find out which version of node is currently running.

If the system version is being used, I want to see the string system.

Ideally, I'm looking for a string to put in my prompt.


回答1:


run this in terminal

nvm current

or

node -v

nvm ls

for list all version

nvm use version_name

for use that version




回答2:


In bash:

[[ $NVM_BIN =~ ([^/]+)/bin$ ]] && echo "${BASH_REMATCH[2]}" || echo "system"

For zsh, first do:

setopt BASH_REMATCH

This is much faster than using nvm current, especially for use in a prompt:

$ time nvm current
system

real    0m0.188s
user    0m0.149s
sys     0m0.042s

Compared with:

$ time [[ $NVM_BIN =~ ([^/]+)/bin$ ]] && echo "${BASH_REMATCH[2]}" || echo "system"

real    0m0.009s
user    0m0.002s
sys     0m0.007s
system

Almost 0.2 seconds vs only 0.009 seconds.



来源:https://stackoverflow.com/questions/53039287/how-do-i-find-the-currently-activated-version-with-nvm

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!