npm을 망쳤어?

17187 단어 npmhomebrewBash
사내에서 공부회가 있고 node.js를 사용한 개발이므로 npm을 사용했는데 공부회의 HandsOn대로 해도 움직이지 않는다.
$ npm install
npm ERR! code E401
npm ERR! Unable to authenticate, need: Basic realm="GitHub Package Registry"

GitHub Packages를 사용하고 있으므로, GITHUB_TOKEN(퍼스널 토큰)을 아래와 같이 써 있었습니다만, 이것이 이용되고 있지 않은 것 같습니다・・・
$ echo "//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}" > ~/.npmrc

음. 모르겠어. 환경을 다시 넣는가?
$ brew install npm
Warning: node 14.12.0 is already installed and up-to-date
To reinstall 14.12.0, run `brew reinstall node`

fromula에 npm
그건 그렇고
$ which npm
/usr/local/bin/npm

homebrew로 넣은 것 같지 않아・・・.
그래, 일단 삭제해.
$ sudo rm -rf /usr/local/bin/npm

터미널을 다시 열어
$ npm -v
-bash: npm: command not found

그래서 homebrew로 node를 재설치하면 어떻게 되겠지 ...

brew reinstall node
==> Downloading https://homebrew.bintray.com/bottles/node-14.12.0.catalina.bottl
Already downloaded: /Users/$USER/Library/Caches/Homebrew/downloads/7f431d50b49d04feb0638fe780f37bce897956fa3641a392c60eb3a90b29b48e--node-14.12.0.catalina.bottle.tar.gz
==> Reinstalling node 
==> Pouring node-14.12.0.catalina.bottle.tar.gz
Warning: The post-install step did not complete successfully
You can try again using `brew postinstall node`
==> Caveats
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d
==> Summary
🍺  /usr/local/Cellar/node/14.12.0: 4,698 files, 62MB


postinstall로 깨진
$ brew postinstall node
==> Postinstalling node
Warning: The post-install step did not complete successfully
You can try again using `brew postinstall node`

왜, 무엇이 이상한가? brew info 명령으로 살펴보기
$ brew info node
node: stable 14.12.0 (bottled), HEAD
Platform built on V8 to build network applications
https://nodejs.org/
/usr/local/Cellar/node/14.12.0 (4,698 files, 62MB) *
  Poured from bottle on 2020-09-24 at 18:35:21
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/node.rb
License: MIT
==> Dependencies
Build: pkg-config ✔, [email protected] ✘
Required: icu4c ✔
==> Options
--HEAD
    Install HEAD version
==> Caveats
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d
==> Analytics
install: 395,225 (30 days), 1,027,480 (90 days), 4,296,784 (365 days)
install-on-request: 285,449 (30 days), 755,473 (90 days), 3,116,512 (365 days)
build-error: 0 (30 days)

파이썬 3.8이 필요하거나 흠.
$ brew install [email protected]
==> Downloading https://homebrew.bintray.com/bottles/gdbm-1.18.1_1.catalina.bott
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/f7b5ab7363961fa6defcb
######################################################################## 100.0%
==> Downloading https://homebrew.bintray.com/bottles/readline-8.0.4.catalina.bot
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/6ae1c8e7c783f32bd22c6
######################################################################## 100.0%
==> Downloading https://homebrew.bintray.com/bottles/sqlite-3.33.0.catalina.bott
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/78566572373e0010a5272
######################################################################## 100.0%
==> Downloading https://homebrew.bintray.com/bottles/xz-5.2.5.catalina.bottle.ta
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/2dcc8e0121c934d1e34ff
######################################################################## 100.0%
Warning: Building [email protected] from source:
  The bottle needs the Apple Command Line Tools to be installed.
  You can install them, if desired, with:
    xcode-select --install

==> Downloading https://files.pythonhosted.org/packages/2f/8e/38259f4a44944a9206
######################################################################## 100.0%
==> Downloading https://files.pythonhosted.org/packages/08/25/f204a6138dade2f675
######################################################################## 100.0%
==> Downloading https://files.pythonhosted.org/packages/75/28/521c6dc7fef23a6836
######################################################################## 100.0%
==> Downloading https://www.python.org/ftp/python/3.8.5/Python-3.8.5.tar.xz
######################################################################## 100.0%
Error: The following formula
  [email protected]
cannot be installed as binary package and must be built from source.
Install the Command Line Tools:
  xcode-select --install

흠흠, 명령 라인 도구가 필요합니다.
$ xcode-select --install
xcode-select: note: install requested for command line developer tools

라고 나와 다이얼로그가・・・. (스크린 샷을 찍지 않았습니다)node 버튼을 클릭하면 라이센스가 나오므로 읽고 install 버튼을 클릭하면
"검색 중"... 그리고 잠시 후
"업데이트 서버를 사용할 수 없으므로 이 소프트웨어를 다운로드할 수 없습니다."
같은 내용의 경고가 나와 설치에 실패하기 힘든 ...
(쿠 ○ Apple 메!)

어쩔 수 없으니 Apple Developers 사이트 에서 Command Line Tools for Xcode12 dmg 파일을 다운로드하여 설치하십시오. (AppleID 필요)
마음을 다시 잡고 python3.8을 넣으십시오.
$ brew install [email protected]
==> Downloading https://homebrew.bintray.com/bottles/gdbm-1.18.1_1.catalina.bott
Already downloaded: /Users/$USER/Library/Caches/Homebrew/downloads/21bd17c428e48bcdca0a388899e5f618c52ea2f80af79fc5bf25f28cd59ca2b2--gdbm-1.18.1_1.catalina.bottle.tar.gz
==> Downloading https://homebrew.bintray.com/bottles/readline-8.0.4.catalina.bot
Already downloaded: /Users/$USER/Library/Caches/Homebrew/downloads/2fd31f598c2c259fa13d0bfb5d6cb892df479dce11424dec3a7af613de062ef2--readline-8.0.4.catalina.bottle.tar.gz
==> Downloading https://homebrew.bintray.com/bottles/sqlite-3.33.0.catalina.bott
Already downloaded: /Users/$USER/Library/Caches/Homebrew/downloads/6802724262549ff9d8bb8483907888d3d4f59b87c720f6e595081ef217c6eb6c--sqlite-3.33.0.catalina.bottle.tar.gz
==> Downloading https://homebrew.bintray.com/bottles/xz-5.2.5.catalina.bottle.ta
Already downloaded: /Users/$USER/Library/Caches/Homebrew/downloads/adc845ca1c49e4b34545aba7f6a277dc85cc30fb3c74a3dda94c823db2ba417e--xz-5.2.5.catalina.bottle.tar.gz
==> Downloading https://homebrew.bintray.com/bottles/python%403.8-3.8.5.catalina
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/3f0592dfdf6bf38c25870
######################################################################## 100.0%
==> Installing dependencies for [email protected]: gdbm, readline, sqlite and xz
==> Installing [email protected] dependency: gdbm
==> Pouring gdbm-1.18.1_1.catalina.bottle.tar.gz
🍺  /usr/local/Cellar/gdbm/1.18.1_1: 25 files, 641KB
==> Installing [email protected] dependency: readline
==> Pouring readline-8.0.4.catalina.bottle.tar.gz
==> Caveats
readline is keg-only, which means it was not symlinked into /usr/local,
because macOS provides BSD libedit.

For compilers to find readline you may need to set:
  export LDFLAGS="-L/usr/local/opt/readline/lib"
  export CPPFLAGS="-I/usr/local/opt/readline/include"

For pkg-config to find readline you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/readline/lib/pkgconfig"

==> Summary
🍺  /usr/local/Cellar/readline/8.0.4: 48 files, 1.5MB
==> Installing [email protected] dependency: sqlite
==> Pouring sqlite-3.33.0.catalina.bottle.tar.gz
==> Caveats
sqlite is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

If you need to have sqlite first in your PATH run:
  echo 'export PATH="/usr/local/opt/sqlite/bin:$PATH"' >> /Users/$USER/.bash_profile

For compilers to find sqlite you may need to set:
  export LDFLAGS="-L/usr/local/opt/sqlite/lib"
  export CPPFLAGS="-I/usr/local/opt/sqlite/include"

For pkg-config to find sqlite you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/sqlite/lib/pkgconfig"

==> Summary
🍺  /usr/local/Cellar/sqlite/3.33.0: 11 files, 4MB
==> Installing [email protected] dependency: xz
==> Pouring xz-5.2.5.catalina.bottle.tar.gz
🍺  /usr/local/Cellar/xz/5.2.5: 92 files, 1.1MB
==> Installing [email protected]
==> Pouring [email protected]
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink bin/2to3
Target /usr/local/bin/2to3
already exists. You may want to remove it:
  rm '/usr/local/bin/2to3'

To force the link and overwrite all conflicting files:
  brew link --overwrite [email protected]

To list all files that would be deleted:
  brew link --overwrite --dry-run [email protected]

Possible conflicting files are:
/usr/local/bin/2to3 -> /Library/Frameworks/Python.framework/Versions/3.7/bin/2to3
/usr/local/bin/idle3 -> /Library/Frameworks/Python.framework/Versions/3.7/bin/idle3
/usr/local/bin/pydoc3 -> /Library/Frameworks/Python.framework/Versions/3.7/bin/pydoc3
/usr/local/bin/python3 -> /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
/usr/local/bin/python3-config -> /Library/Frameworks/Python.framework/Versions/3.7/bin/python3-config
Error: Permission denied @ dir_s_mkdir - /usr/local/Frameworks

··· 이미 설치하고 있던 Python3.7와 함께 Conflict···orz
파이썬 올리기 · · 파이썬 공식 다운로드 사이트 (for MacOS)
brew postinstall node
==> Postinstalling node
Warning: The post-install step did not complete successfully
You can try again using `brew postinstall node`

안돼 orz

일단 postinstall을 포기하고 일단 npm을 움직이는 것을 목표로합니다. 同意する 에서 현재 상황을 확인.
$ brew info node
node: stable 14.12.0 (bottled), HEAD
Platform built on V8 to build network applications
https://nodejs.org/
/usr/local/Cellar/node/14.12.0 (4,698 files, 62MB) *
  Poured from bottle on 2020-09-24 at 18:35:21
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/node.rb
License: MIT
==> Dependencies
Build: pkg-config ✔, [email protected] ✔
Required: icu4c ✔
==> Options
--HEAD
    Install HEAD version
==> Caveats
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d
==> Analytics
install: 395,225 (30 days), 1,027,480 (90 days), 4,296,784 (365 days)
install-on-request: 285,449 (30 days), 755,473 (90 days), 3,116,512 (365 days)
build-error: 0 (30 days)

의존성은 해결한 것 같다. node가 brew로 설치된 위치를 찾아보세요
$ ls /usr/local/Cellar/node/14.12.0/
AUTHORS         README.md       lib
CHANGELOG.md        bin         libexec
INSTALL_RECEIPT.json    etc         share
LICENSE         include

$ ls -l /usr/local/Cellar/node/14.12.0/libexec/bin
total 0
lrwxr-xr-x  1 $user  316702609  38  9 22 11:22 npm -> ../lib/node_modules/npm/bin/npm-cli.js
lrwxr-xr-x  1 $user  316702609  38  9 22 11:22 npx -> ../lib/node_modules/npm/bin/npx-cli.js


있었다! PATH를 통해 ...
$ export PATH="/usr/local/Cellar/node/14.12.0/libexec/bin:$PATH"

npm 명령 실행!!
$ npm -v
6.14.8

낫다 아 아 아

.bash_profile에 이전의 export 명령을 추가하여 새로운 터미널 창을 열고 적절한 node.js가 실행되는 디렉토리에 액세스하여 npm start를 시도합니다 ...
$ cd /path/to/app
$ npm start

무사히 움직였습니다 · · ·

그럼, 건(쿠단)의 어플리케이션은?
$ cd /path/to/another/app
$ npm install
npm ERR! code E401
npm ERR! Unable to authenticate, need: Basic realm="GitHub Package Registry"

안돼 orz

github의 개인 액세스 토큰 목록을 보면 brew info node

좋은 웹페이지 즐겨찾기