본문 바로가기

DEVELOP

[Node.js] nvm 대신 fnm을 써보자

728x90

nvm는 node version manger로서 프로젝트마다 노드버전을 달리할 때 프로젝트 별 맞는 버전을 그때그때 변환하기 쉽게 관리하는데 도움을 준다.

최근에(?) 알게된 노드 관리자로서 fnm을 알게되었는데 nvm 보다는 속도도 빠르고 가볍다고 한다. 사실 차이를 잘 모르겠지만 nvm이랑 거의 비슷한거 같다. 

프로젝트 중에 node version이 16.18.32 인 플젝이 있어서 새로운 로컬에 설치할 상황이 생겨 테스트겸 fnm을 사용해 보았다.

1. fnm download

# fnm 다운로드 및 설치
winget install Schniz.fnm

 

2. fnm 으로 원하는 버전 설치

fnm i 16.18.32

 

위와 같이 입력하면 윈도우 64비트일 경우, 아래와 같은 에러가 나올 것이다. 

Installing Node v16.18.32 (x64)
error: Can't download the requested binary: v16.18.32 for x64 not found upstream.
You can `fnm ls-remote` to see available versions or try a different `--arch`.

 

운영체제 환경에 따라 다운 받을 수 있는 버전이 존재한다. 버전 목록을 보려면 아래와 같이 명령어를 입력한다.

fnm ls-remote

 

입력하면 version 0 부터 쭉 나올 것이다.

여기서 기존 프로젝트 노드 버전과 똑같은 버전이 있으면 설치하고 없다면 흡사한 버전으로 설치.

16.18.32 와 흡사한 16.18.1 을 설치해보았다.

fnm use 16.18.1

 

하지만.. 아래와 같은 에러가 나온다.

error: We can't find the necessary environment variables to replace the Node ver
sion.
You should setup your shell profile to evaluate `fnm env`, see https://github.co
m/Schniz/fnm#shell-setup on how to do this
Check out our documentation for more information: https://fnm.vercel.app

 

열심히 또 구글링...

 

아래 내용으로 해결하였다.

https://github.com/Schniz/fnm/issues/1190#issuecomment-2475527015

 

Only 'fnm use' returns error "We can't find the necessary environment variables to replace the Node version" · Issue #1190 · S

Description: It used to work fine and could show a warning about the recommended node version based on .nvmrc in the zsh shell but not the bash shell even though I configured both. The problem occu...

github.com

hu-qi님의 글로 말끔히 해결!

 

아래의 명령어를 한줄 추가해주면 된다.

$ eval "$(fnm env --use-on-cd --version-file-strategy=recursive)"

 

그리고 다시 16.18.1 버전 사용 시도

fnm use 16.18.1

 

해당 프로젝트 안에서 노드 버전 확인

node -v
v16.18.1

 

😊