2013-03-19 174 views
16

嘗試安裝NPM時收到此錯誤。任何關於這個錯誤的幫助,我們都非常感謝無法使用捲曲安裝NPM

$ 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>' 

將命令從http:// ... - > https://更改並仍然沒有運氣。


其他信息:

操作系統:Mac OSX 10.8.2

捲曲:捲曲7.24.0(x86_64的 - 蘋果darwin12.0)


所以我試圖以超級用戶的身份進行安裝,並很快遇到了這個山峯的文字。我完全迷失在這裏。

$ 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 [email protected]" 
    t=1.0 
    ;; 
v0.[678].* | 0.[678].*) 
    echo "install [email protected]" 
    t=1.1 
    ;; 
*) 
    echo "install [email protected]" 
    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 
+1

就這些?沒有操作系統,沒有捲曲版本,沒有外殼名稱/版本? – 2013-03-19 19:01:24

+0

@sputnick,更新操作系統和捲曲版本。不知道您的shell名稱/版本是什麼意思。如果有幫助,我使用iTerm。我還添加了在su中運行命令時發生的情況。 – ryanSrich 2013-03-19 19:16:32

回答

46

您正在獲取install.sh腳本,您只需執行它。

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

不起作用用'下載一個nginx文件301永久移動' – ThomasReggi 2014-03-13 22:27:28

+0

@ThomasReggi你的問題似乎與問題中提出的問題完全不同。這也適用於我。你應該問一個新的問題,提供你的問題的細節。 – user568109 2014-03-14 04:27:48

+0

@ThomasReggi查看最新的答案,如果它適合你。 – user568109 2014-03-14 04:34:52

2

原:如果你會被永久移動了301文件,而不是,嘗試添加-L選項遵循這樣的重定向做到這一點

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

更新

命令將工作,如果你使用當前的位置(而不是舊的)(至少在我的系統,相同的設置)。 含義,用途:用於

curl https://npmjs.org/install.sh | sh 

代替:

curl http://npmjs.org/install.sh | sh 
+1

在問題中,OP已經嘗試** https ** – Raptor 2013-08-16 10:03:41

+0

我看到他做到了。但是,它對我來說工作得很好。 – 2013-08-17 20:04:19

+0

這不起作用 - 擊中http:/位置會返回明確的使用說明https:/ – mmmeff 2013-11-10 19:22:48

1

這仍然是斷開不知何故?嘗試以下操作:

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

,並與(HTTPS)www.npmjs.org:

$curl https://www.npmjs.org/install.sh | sh 
    % Total % Received % Xferd Average Speed Time Time  Time Current 
          Dload Upload Total Spent Left Speed 
100 6707 100 6707 0  0 6446  0 0:00:01 0:00:01 --:--:-- 6442 
npm-install-606.sh: line 1: syntax error near unexpected token `newline' 
npm-install-606.sh: line 1: `<html>Moved: <a href="https://www.npmjs.org/install.sh">https://www.npmjs.org/install.sh</a>' 

使用OS X 10.9.1 Maverics

$uname -a 
Darwin Esan-iMac.local 13.0.0 Darwin Kernel Version 13.0.0: Thu Sep 19 22:22:27 PDT 2013; root:xnu-2422.1.72~6/RELEASE_X86_64 x86_64 

$curl --version 
curl 7.30.0 (x86_64-apple-darwin13.0) libcurl/7.30.0 SecureTransport zlib/1.2.5 

它應該有類似ENV工作;有人測試? 我錯過了什麼。記住,用sudo運行是不鼓勵的? 尚未嘗試單獨下載和'sh'命令。


編輯:是的,單獨的下載curl -O https://www.npmjs.org/install.shsh install.sh工作得很好,因爲以前用sudo安裝變化所有者/usr/local/lib/node_modules/npm後。但它與錯誤信息無關,或者可以嗎?

1

我已經嘗試了很多次,各種捲曲選項。但主要問題是npm站點的https證書驗證。最後這對我有效:

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

希望它能幫助別人。

0

添加-L幫助了我。例如:

curl -L http://www.npmjs.org/install.sh | sh