NPM使用curl无法安装 [英] Cannot install NPM using curl

查看:1107
本文介绍了NPM使用curl无法安装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试安装NPM时收到此错误。关于此错误的任何帮助是极大AP preciated。

  $卷曲http://npmjs.org/install.sh | SH
%总计%接受%Xferd平均速度时间时间时间电流
                             DLOAD上传一共花左速度
100 85 0 85 0 0 2226 0 - : - : - - : - : - - : - : - 4473
SH:第1行:附近意外的标记'换行语法错误
SH:第1行:`&LT; HTML和GT;移动:LT; A HREF =htt​​ps://npmjs.org/install.sh&GT;的https://npmjs.org/install.sh< / A&GT;'

从http改变了命令:// ... - > https://开头,仍然没有运气。


其他信息:

操作系统:Mac OSX 10.8.2

卷曲:卷曲7.24.0下(x86_64-苹果darwin12.0)


所以我试图安装一个超级用户,并立即会见了此山的文字。我完全失去了这里。

  $ sudo的卷曲https://npmjs.org/install.sh | SH
密码:
#!/ bin / sh的#这个shell脚本,一个字:

#它必须到处工作,包括缺乏系统
#A /斌/ bash中,地图'上海'来的ksh,ksh97,庆典,灰,或zsh的,
#和潜在有一张POSIX外壳或Bourne
#壳住在/ bin / sh的。

#查看编写可移植的shell脚本这是很有帮助的文件:
#http://www.gnu.org/s/hello/manual/autoconf/Portable-Shell.html

#它永远不会工作,对唯一的外壳cmd.exe的。如果[X $ 0=XSH];然后
  #运行方式卷曲| SH
  #在一些系统中,你可以做猫&GT; npm-install.sh
      #这是一个有点可爱。但是对别人,和放大器; 1已经关闭,
  #所以catting到另一个脚本文件不会做任何事情。
  卷曲-s https://npmjs.org/install.sh&GT; NPM-安装 - $$ SH
  SH NPM-安装 - $$ SH
  RET = $?
  RM NPM-安装 - $$ SH
  退出$沤
科幻#看看npm_config_ *的东西中有包膜,
#并使其永久化。
#如果失败,这不是什么大不了的。
配置=`ENV | grep的npm_config_'| sed的-e的| ^ npm_config_ || g'`npm_config_loglevel =错误
如果[X $ npm_debug=X];然后
  (退出0)
其他
  回声在调试模式下运行。
  回声请注意,这需要bash或zsh的。
  设置-o X跟踪
  设置-o pipefail
  npm_config_loglevel =详细
科幻
出口npm_config_loglevel#确保节点存在
节点=`哪个节点2 - ;&安培; 1`
RET = $?
    如果[$沤-eq 0]放大器;&安培; [-x$节点];然后
  (退出0)
    其他
  回声NPM不能在没有安装的NodeJS。 &GT;和2
  回声首先安装节点,然后再试一次。 &GT;和2
  回声&GT;和2
  回声也许是安装的节点,而不是在路径? &GT;和2
  回声请注意,运行和sudo的可以改变ENVS。 &GT;和2
  回声
  回声PATH = $ PATH&GT;和2
  退出$沤
科幻#设置临时目录
TMP =$ {} TMPDIR
如果[X $ TMP=X];然后
  TMP =/ tmp目录
科幻
TMP =$ {} TMP / NPM。$$
室射频$ TMP||真正
MKDIR$ TMP
如果[$? -ne 0];然后
  回声未能MKDIR $ TMP&GT;和2
  1号出口
科幻BACK =$ PWDRET = 0
焦油=$ {} TAR
如果[-z$焦油];然后
  焦油=$ {} npm_config_tar
科幻
如果[-z$焦油];然后
  焦油=`其中焦油2 - ;&安培; 1`
  RET = $?
科幻如果[$沤-eq 0]放大器;&安培; [-x$焦油];然后
  回声焦油= $焦油
  回声版本:
      $焦油--version
  RET = $?
科幻如果[$沤-eq 0];然后
  (退出0)
其他
  回声没有合适的tar程序中。
      1号出口
    科幻#尝试找到一个合适的化妆
#如果MAKE环境变量被设置,使用它。
#否则,试图找到gmake命令,然后进行。
#如果发现没有化妆,然后就执行必要的命令。#XXX出于某种原因,使每一次构建所有的文档。这个
    #是错误的一个恼人的来源。弄清楚为什么会这样。
MAKE = NOMAKE如果[X $ MAKE=X];然后
  使=`这GMAKE 2 - ;&安培; 1`
  如果[$? -eq 0]放大器;&安培; [-x $做出]然后
(退出0)
  其他
使=`这使得2 - ;&安培; 1`
如果[$? -eq 0]放大器;&安培; [-x $做出]然后
  (退出0)
其他
  使= NOMAKE
科幻
  科幻
其他
  令=$ MAKE
科幻如果[-x$使];然后
  (退出0)
其他
  #回声安装没有做出。这可能会失败。 &GT;和2
      使= NOMAKE
科幻#如果没有庆典,那么甚至不尝试清洁
如果[-x/斌/ bash的];然后
  (退出0)
其他
  清洁=NO
科幻node_version =`$节点--version 2 - ;&安培; 1`
RET = $?
如果[$沤-ne 0];然后
  回声您需要节点运行此程序。 &GT;和2
  回声节点--version报道:$ node_version&GT;和2
  回声,退出code = $沤&GT;和2
  回声请继续之前安装的节点。 &GT;和2
  退出$沤
科幻T =$ {} npm_install
    如果[-z$ T];然后
  #开关基于节点的版本。
  #注意,我们只可以在这里使用严格sh兼容的模式。
  万一$ node_version
    0 [0123] *。| V0 [0123]。*)
  回声您正在使用的过时和不支持的版本&GT;和2
  回声节点($ node_version)。请更新节点,然后再试一次。 &GT;和2
  出口99
  ;;
V0 [45] *。。| 0 [45]。*)
  回声安装npm@1.0
  T = 1.0
  ;;
。V0 [678]。* | 0 [678]。*)
  回声安装npm@1.1
  T = 1.1
  ;;
*)
  回声故宫安装最新@
  T =最新
  ;;
  ESAC
科幻#在npmca证书
CACERT ='
----- BEGIN CERTIFICATE -----
MIIChzCCAfACCQDauvz / KHp8ejANBgkqhkiG9w0BAQUFADCBhzELMAkGA1UEBhMC
VVMxCzAJBgNVBAgTAkNBMRAwDgYDVQQHEwdPYWtsYW5kMQwwCgYDVQQKEwNucG​​0x
IjAgBgNVBAsTGW5wbSBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkxDjAMBgNVBAMTBW5w
bUNBMRcwFQYJKoZIhvcNAQkBFghpQGl6cy5tZTAeFw0xMTA5MDUwMTQ3MTdaFw0y
MTA5MDIwMTQ3MTdaMIGHMQswCQYDVQQGEwJVUzELMAkGA1UECBMCQ0ExEDAOBgNV
BAcTB09ha2xhbmQxDDAKBgNVBAoTA25wbTEiMCAGA1UECxMZbnBtIENlcnRpZmlj
YXRlIEF1dGhvcml0eTEOMAwGA1UEAxMFbnBtQ0ExFzAVBgkqhkiG9w0BCQEWCGlA
aXpzLm1lMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDLI4tIqPpRW + ACw9GE
OgBlJZwK5f8nnKCLK629Pv5yJpQKs3DENExAyOgDcyaF0HD0zk8zTp + ZsLaNdKOz
Gn2U181KGprGKAXP6DU6ByOJDWmTlY6 + Ad1laYT0m64fERSpHw / hjD3D + iX4aMOl
y0HdbT5m1ZGh6SJz3ZqxavhHLQIDAQABMA0GCSqGSIb3DQEBBQUAA4GBAC4ySDbC
l7W1WpLmtLGEQ / yuMLUf6Jy / VR + CRp4h + UZL + IQpCv8FfxsYE7dhf / bmWTEupBkv
yNL18lipt2jSvR3v6oAHAReotvdjqhxddpe5Holns6EQd1 / xEZ7sB1YhQKJtvUrl
ZNufy1Jf1r0ldEGeA + 0ISck7s + xSh9rQD2Op
----- END CERTIFICATE -----
回声$ CACERT&GT; $ TMP / cafile.crt
CACERT =$ TMP / cafile.crt#需要回声后,因为SED的Posix不把EOF
#为线的暗示结束。
URL =`(卷曲-ssl --cacert$ CACERThttps://registry.npmjs.org/npm/$t;回声)\\
 | SED -e的/^.*压缩包://\\
 | SED -e的/\".*$//'`RET = $?
如果[X $网址=X];然后
  RET = 125
  #尝试没有-e个参数的sed。
  URL =`(卷曲-ssl --cacert$ CACERThttps://registry.npmjs.org/npm/$t;回声)\\
   | SED的/^.*压缩包://\\
   | SED的/\".*$//'`
  RET = $?
  如果[X $网址=X];然后
RET = 125
  科幻
科幻
如果[$沤-ne 0];然后
  回声无法获得NPM / $ T压缩包网址&GT;和2
  退出$沤
科幻
回声取:$网址&GT;和2CD$ TMP\\
  &功放;&安培;卷曲-ssl --cacert$ CACERT,$网址​​\\
 | $焦油-xzf - \\
  &功放;&安培; RM$ CACERT\\
  &功放;&安培; CD$ TMP/ * \\
  &功放;&安培; (REQ =`$节点的bin /读取包json.js的package.json engines.node`
  如果[-d node_modules]然后
    $节点node_modules / semver /斌/ semver -v$ node_version-r$ REQ
    RET = $?
  其他
    $节点的bin / semver.js -v$ node_version-r$ REQ
    RET = $?
  科幻
  如果[$沤-ne 0];然后
    回声你需要节点$ REQ运行此程序。 &GT;和2
    回声节点--version报道:$ node_version&GT;和2
    回声继续前请升级节点。 &GT;和2
    退出$沤
  FI)\\
  &功放;&安培; (VER =`$节点的bin /读取包json.js的package.json version`
  isnpm10 = 0
  如果[$沤-eq 0];然后
    REQ =`$节点的bin /读取包json.js的package.json engines.node`
    如果[-d node_modules]然后
      如果$节点node_modules / semver /斌/ semver -v$版本-R1
      然后
        isnpm10 = 1
      科幻
    其他
      如果$节点的bin / semver -v$版本-r&GT; = 1.0;然后
        isnpm10 = 1
      科幻
    科幻
  科幻  RET = 0
  如果[$ isnpm10 -eq 1]安培;&安培; [-f脚本/ clean-old.sh];然后
    如果[X $ skipclean=X];然后
      (退出0)
    其他
      干净=无
    科幻
    如果[X $干净=XNO] \\
        || [X $干净=XN];然后
      回声跳过0.X克鲁夫特干净&GT;和2
      RET = 0
    ELIF [X $干净=XY] || [X $干净=xyes];然后
      NODE =$节点/斌/ bash的脚本/ clean-old.sh-y
      RET = $?
    其他
      NODE =$节点/斌/ bash的脚本/ clean-old.sh&LT;为/ dev / tty的
      RET = $?
    科幻
  科幻  如果[$沤-ne 0];然后
    回声中止0.X清理工作。退出。 &GT;和2
    退出$沤
  FI)\\
  &功放;&安培; (如果[×$提供配置=×];然后
    (退出0)
  其他
    回声的./configure$提供配置
    回声$提供配置&GT; npmrc
  FI)\\
  &功放;&安培; (如果[$使=NOMAKE];然后
    (退出0)
  ELIF$使卸载安装;然后
    (退出0)
  其他
    令=NOMAKE
  科幻
  如果[$使=NOMAKE];然后
    $节点cli.js RM NPM -gf
    $节点cli.js安装-gf
  FI)\\
  &功放;&安培; CD$ BACK\\
  &功放;&安培;室射频$ TMP\\
  &功放;&安培;回声它的工作RET = $?
如果[$沤-ne 0];然后
  回声它没有&GT;和2
科幻
退出$沤


解决方案

您所得到的install.sh脚本,你只需要执行它。做到这一点

 卷曲-O https://npmjs.org/install.sh
须藤SH install.sh


更新

如果你得到永久移动301文件,而不是,尝试添加-L选项遵循这样的重定向:

 卷曲-O -L https://npmjs.org/install.sh

Receiving this error when attempting to install NPM. Any help on this error is greatly appreciated.

$ curl http://npmjs.org/install.sh | sh
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                             Dload  Upload   Total   Spent    Left  Speed
100    85    0    85    0     0   2226      0 --:--:-- --:--:-- --:--:--  4473
sh: line 1: syntax error near unexpected token `newline'
sh: line 1: `<html>Moved: <a href="https://npmjs.org/install.sh">https://npmjs.org/install.sh</a>'

Changed the command from http://... --> https:// and still no luck.


Other info:

OS: Mac OSX 10.8.2

CURL: curl 7.24.0 (x86_64-apple-darwin12.0)


So I attempted the install as a superuser and was promptly met with this mountain of text. I'm completely lost here.

$ sudo curl https://npmjs.org/install.sh | sh
Password:
#!/bin/sh

# A word about this shell script:
#
# It must work everywhere, including on systems that lack
# a /bin/bash, map 'sh' to ksh, ksh97, bash, ash, or zsh,
# and potentially have either a posix shell or bourne
# shell living at /bin/sh.
#
# See this helpful document on writing portable shell scripts:
# http://www.gnu.org/s/hello/manual/autoconf/Portable-Shell.html
#
# The only shell it won't ever work on is cmd.exe.

if [ "x$0" = "xsh" ]; then
  # run as curl | sh
  # on some systems, you can just do cat>npm-install.sh
      # which is a bit cuter.  But on others, &1 is already closed,
  # so catting to another script file won't do anything.
  curl -s https://npmjs.org/install.sh > npm-install-$$.sh
  sh npm-install-$$.sh
  ret=$?
  rm npm-install-$$.sh
  exit $ret
fi

# See what "npm_config_*" things there are in the env,
# and make them permanent.
# If this fails, it's not such a big deal.
configures="`env | grep 'npm_config_' | sed -e 's|^npm_config_||g'`"

npm_config_loglevel="error"
if [ "x$npm_debug" = "x" ]; then
  (exit 0)
else
  echo "Running in debug mode."
  echo "Note that this requires bash or zsh."
  set -o xtrace
  set -o pipefail
  npm_config_loglevel="verbose"
fi
export npm_config_loglevel

# make sure that node exists
node=`which node 2>&1`
ret=$?
    if [ $ret -eq 0 ] && [ -x "$node" ]; then
  (exit 0)
    else
  echo "npm cannot be installed without nodejs." >&2
  echo "Install node first, and then try again." >&2
  echo "" >&2
  echo "Maybe node is installed, but not in the PATH?" >&2
  echo "Note that running as sudo can change envs." >&2
  echo ""
  echo "PATH=$PATH" >&2
  exit $ret
fi

# set the temp dir
TMP="${TMPDIR}"
if [ "x$TMP" = "x" ]; then
  TMP="/tmp"
fi
TMP="${TMP}/npm.$$"
rm -rf "$TMP" || true
mkdir "$TMP"
if [ $? -ne 0 ]; then
  echo "failed to mkdir $TMP" >&2
  exit 1
fi

BACK="$PWD"

ret=0
tar="${TAR}"
if [ -z "$tar" ]; then
  tar="${npm_config_tar}"
fi
if [ -z "$tar" ]; then
  tar=`which tar 2>&1`
  ret=$?
fi

if [ $ret -eq 0 ] && [ -x "$tar" ]; then
  echo "tar=$tar"
  echo "version:"
      $tar --version
  ret=$?
fi

if [ $ret -eq 0 ]; then
  (exit 0)
else
  echo "No suitable tar program found."
      exit 1
    fi



# Try to find a suitable make
# If the MAKE environment var is set, use that.
# otherwise, try to find gmake, and then make.
# If no make is found, then just execute the necessary commands.

# XXX For some reason, make is building all the docs every time.  This
    # is an annoying source of bugs. Figure out why this happens.
MAKE=NOMAKE

if [ "x$MAKE" = "x" ]; then
  make=`which gmake 2>&1`
  if [ $? -eq 0 ] && [ -x $make ]; then
(exit 0)
  else
make=`which make 2>&1`
if [ $? -eq 0 ] && [ -x $make ]; then
  (exit 0)
else
  make=NOMAKE
fi
  fi
else
  make="$MAKE"
fi

if [ -x "$make" ]; then
  (exit 0)
else
  # echo "Installing without make. This may fail." >&2
      make=NOMAKE
fi

# If there's no bash, then don't even try to clean
if [ -x "/bin/bash" ]; then
  (exit 0)
else
  clean="no"
fi

node_version=`"$node" --version 2>&1`
ret=$?
if [ $ret -ne 0 ]; then
  echo "You need node to run this program." >&2
  echo "node --version reports: $node_version" >&2
  echo "with exit code = $ret" >&2
  echo "Please install node before continuing." >&2
  exit $ret
fi

t="${npm_install}"
    if [ -z "$t" ]; then
  # switch based on node version.
  # note that we can only use strict sh-compatible patterns here.
  case $node_version in
    0.[0123].* | v0.[0123].*)
  echo "You are using an outdated and unsupported version of" >&2
  echo "node ($node_version).  Please update node and try again." >&2
  exit 99
  ;;
v0.[45].* | 0.[45].*)
  echo "install npm@1.0"
  t=1.0
  ;;
v0.[678].* | 0.[678].*)
  echo "install npm@1.1"
  t=1.1
  ;;
*)
  echo "install npm@latest"
  t="latest"
  ;;
  esac
fi

# the npmca cert
cacert='
-----BEGIN CERTIFICATE-----
MIIChzCCAfACCQDauvz/KHp8ejANBgkqhkiG9w0BAQUFADCBhzELMAkGA1UEBhMC
VVMxCzAJBgNVBAgTAkNBMRAwDgYDVQQHEwdPYWtsYW5kMQwwCgYDVQQKEwNucG0x
IjAgBgNVBAsTGW5wbSBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkxDjAMBgNVBAMTBW5w
bUNBMRcwFQYJKoZIhvcNAQkBFghpQGl6cy5tZTAeFw0xMTA5MDUwMTQ3MTdaFw0y
MTA5MDIwMTQ3MTdaMIGHMQswCQYDVQQGEwJVUzELMAkGA1UECBMCQ0ExEDAOBgNV
BAcTB09ha2xhbmQxDDAKBgNVBAoTA25wbTEiMCAGA1UECxMZbnBtIENlcnRpZmlj
YXRlIEF1dGhvcml0eTEOMAwGA1UEAxMFbnBtQ0ExFzAVBgkqhkiG9w0BCQEWCGlA
aXpzLm1lMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDLI4tIqPpRW+ACw9GE
OgBlJZwK5f8nnKCLK629Pv5yJpQKs3DENExAyOgDcyaF0HD0zk8zTp+ZsLaNdKOz
Gn2U181KGprGKAXP6DU6ByOJDWmTlY6+Ad1laYT0m64fERSpHw/hjD3D+iX4aMOl
y0HdbT5m1ZGh6SJz3ZqxavhHLQIDAQABMA0GCSqGSIb3DQEBBQUAA4GBAC4ySDbC
l7W1WpLmtLGEQ/yuMLUf6Jy/vr+CRp4h+UzL+IQpCv8FfxsYE7dhf/bmWTEupBkv
yNL18lipt2jSvR3v6oAHAReotvdjqhxddpe5Holns6EQd1/xEZ7sB1YhQKJtvUrl
ZNufy1Jf1r0ldEGeA+0ISck7s+xSh9rQD2Op
-----END CERTIFICATE-----
'

echo "$cacert" > "$TMP/cafile.crt"
cacert="$TMP/cafile.crt"

# need to echo "" after, because Posix sed doesn't treat EOF
# as an implied end of line.
url=`(curl -SsL --cacert "$cacert" https://registry.npmjs.org/npm/$t; echo "") \
 | sed -e 's/^.*tarball":"//' \
 | sed -e 's/".*$//'`

ret=$?
if [ "x$url" = "x" ]; then
  ret=125
  # try without the -e arg to sed.
  url=`(curl -SsL --cacert "$cacert" https://registry.npmjs.org/npm/$t; echo "") \
   | sed 's/^.*tarball":"//' \
   | sed 's/".*$//'`
  ret=$?
  if [ "x$url" = "x" ]; then
ret=125
  fi
fi
if [ $ret -ne 0 ]; then
  echo "Failed to get tarball url for npm/$t" >&2
  exit $ret
fi


echo "fetching: $url" >&2

cd "$TMP" \
  && curl -SsL --cacert "$cacert" "$url" \
 | $tar -xzf - \
  && rm "$cacert" \
  && cd "$TMP"/* \
  && (req=`"$node" bin/read-package-json.js package.json engines.node`
  if [ -d node_modules ]; then
    "$node" node_modules/semver/bin/semver -v "$node_version" -r "$req"
    ret=$?
  else
    "$node" bin/semver.js -v "$node_version" -r "$req"
    ret=$?
  fi
  if [ $ret -ne 0 ]; then
    echo "You need node $req to run this program." >&2
    echo "node --version reports: $node_version" >&2
    echo "Please upgrade node before continuing." >&2
    exit $ret
  fi) \
  && (ver=`"$node" bin/read-package-json.js package.json version`
  isnpm10=0
  if [ $ret -eq 0 ]; then
    req=`"$node" bin/read-package-json.js package.json engines.node`
    if [ -d node_modules ]; then
      if "$node" node_modules/semver/bin/semver -v "$ver" -r "1"
      then
        isnpm10=1
      fi
    else
      if "$node" bin/semver -v "$ver" -r ">=1.0"; then
        isnpm10=1
      fi
    fi
  fi

  ret=0
  if [ $isnpm10 -eq 1 ] && [ -f "scripts/clean-old.sh" ]; then
    if [ "x$skipclean" = "x" ]; then
      (exit 0)
    else
      clean=no
    fi
    if [ "x$clean" = "xno" ] \
        || [ "x$clean" = "xn" ]; then
      echo "Skipping 0.x cruft clean" >&2
      ret=0
    elif [ "x$clean" = "xy" ] || [ "x$clean" = "xyes" ]; then
      NODE="$node" /bin/bash "scripts/clean-old.sh" "-y"
      ret=$?
    else
      NODE="$node" /bin/bash "scripts/clean-old.sh" </dev/tty
      ret=$?
    fi
  fi

  if [ $ret -ne 0 ]; then
    echo "Aborted 0.x cleanup.  Exiting." >&2
    exit $ret
  fi) \
  && (if [ "x$configures" = "x" ]; then
    (exit 0)
  else
    echo "./configure "$configures
    echo "$configures" > npmrc
  fi) \
  && (if [ "$make" = "NOMAKE" ]; then
    (exit 0)
  elif "$make" uninstall install; then
    (exit 0)
  else
    make="NOMAKE"
  fi
  if [ "$make" = "NOMAKE" ]; then
    "$node" cli.js rm npm -gf
    "$node" cli.js install -gf
  fi) \
  && cd "$BACK" \
  && rm -rf "$TMP" \
  && echo "It worked"

ret=$?
if [ $ret -ne 0 ]; then
  echo "It failed" >&2
fi
exit $ret

解决方案

You are getting the install.sh script, you just have to execute it. Do this

curl -O https://npmjs.org/install.sh
sudo sh install.sh


Update

If you get a 301 Moved Permanently file instead, try adding -L option to follow the redirect like this:

curl -O -L https://npmjs.org/install.sh

这篇关于NPM使用curl无法安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆