wscat

wscat 是一个用于 WebSocket 通信测试的命令行工具

安装wscat

flynnsin@flynnsin:~$ sudo npm install -g wscat
loadDep:ws → afterAdd     ▄ ╢████████████████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░╟
npm ERR! Linux 5.4.0-150-generic
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "install" "-g" "wscat"
npm ERR! node v8.10.0
npm ERR! npm  v3.5.2
npm ERR! code EMISSINGARG

npm ERR! typeerror Error: Missing required argument #1
npm ERR! typeerror     at andLogAndFinish (/usr/share/npm/lib/fetch-package-metadata.js:31:3)
npm ERR! typeerror     at fetchPackageMetadata (/usr/share/npm/lib/fetch-package-metadata.js:51:22)
npm ERR! typeerror     at resolveWithNewModule (/usr/share/npm/lib/install/deps.js:456:12)
npm ERR! typeerror     at /usr/share/npm/lib/install/deps.js:457:7
npm ERR! typeerror     at /usr/share/npm/node_modules/iferr/index.js:13:50
npm ERR! typeerror     at /usr/share/npm/lib/fetch-package-metadata.js:37:12
npm ERR! typeerror     at addRequestedAndFinish (/usr/share/npm/lib/fetch-package-metadata.js:82:5)
npm ERR! typeerror     at returnAndAddMetadata (/usr/share/npm/lib/fetch-package-metadata.js:117:7)
npm ERR! typeerror     at pickVersionFromRegistryDocument (/usr/share/npm/lib/fetch-package-metadata.js:134:20)
npm ERR! typeerror     at /usr/share/npm/node_modules/iferr/index.js:13:50
npm ERR! typeerror This is an error with npm itself. Please report this error at:
npm ERR! typeerror     

npm ERR! Please include the following file with any support request:
npm ERR!     /home/flynnsin/npm-debug.log

安装nvm

sudo curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 15037  100 15037    0     0  10634      0  0:00:01  0:00:01 --:--:-- 10634
=> nvm is already installed in /home/flynnsin/.nvm, trying to update using git
=>   master

* (头指针分离于 FETCH_HEAD)
  => Compressing and cleaning up git repository

=> Appending nvm source string to /home/flynnsin/.bashrc
=> Appending bash_completion source string to /home/flynnsin/.bashrc
=> Close and reopen your terminal to start using nvm or run the following to use it now:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
flynnsin@flynnsin:~/tool$ 

安装新版

export NVM_DIR="$HOME/.nvm"
flynnsin@flynnsin:~/tool$ [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # 这将加载 nvm
flynnsin@flynnsin:~/tool$ [ -s "$NVM_DIR/bash_completion" ] &&\. "$NVM_DIR/bash_completion" # 这将加载 nvm bash_completion
flynnsin@flynnsin:~/tool$ nvm current
system
flynnsin@flynnsin:~/tool$ nvm install --lts
Installing latest LTS version.
Downloading and installing node v20.9.0...
Downloading https://nodejs.org/dist/v20.9.0/node-v20.9.0-linux-x64.tar.xz...
############################################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v20.9.0 (npm v)
Creating default alias: default -> lts/* (-> v20.9.0)

新版不支持

flynnsin@flynnsin:~/tool$ node -v
node: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.28' not found (required by node)
flynnsin@flynnsin:~/tool$ sudo npm install -g wscat
sudo: npm:找不到命令
flynnsin@flynnsin:~/tool$ npm install -g wscat
node: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.28' not found (required by node)
flynnsin@flynnsin:~/tool$ nvm ls-remote

安装稳定版

flynnsin@flynnsin:~/tool$ nvm install lts/erbium
Downloading and installing node v12.22.12...
Downloading https://nodejs.org/dist/v12.22.12/node-v12.22.12-linux-x64.tar.xz...
############################################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v12.22.12 (npm v6.14.16)
flynnsin@flynnsin:~/tool$ nvm use lts/erbium
Now using node v12.22.12 (npm v6.14.16)
flynnsin@flynnsin:~/tool$ node -v
v12.22.12
flynnsin@flynnsin:~/tool$ npm install -g wscat
/home/flynnsin/.nvm/versions/node/v12.22.12/bin/wscat -> /home/flynnsin/.nvm/versions/node/v12.22.12/lib/node_modules/wscat/bin/wscat
+ [email protected]
added 9 packages from 7 contributors in 4.749s
flynnsin@flynnsin:~/tool$ wscat ^C

只能一个终端使用 node,修改默认

nvm ls
      v12.22.12
        v20.9.0
         system
default -> lts/* (-> v20.9.0)

怎么更改这个 default版本
ChatGPT
要更改 nvm 的默认 Node.js 版本,您可以使用以下命令:

bash
Copy code
nvm alias default [新Node.js版本号]

记得退出终端

flynnsin@flynnsin:~/tool$ node -v
v12.22.12

在这里插入图片描述

你可能感兴趣的:(linux)