nvm doesn't work with curl alias

Created on 7 Jul 2016  ·  11Comments  ·  Source: nvm-sh/nvm

I have curl aliased in my shell:

dan-mbp-work:~ dan$ type curl
curl is aliased to `curl --verbose -k -o/dev/null'
dan-mbp-work:~ dan$ 

This causes nvm to fail on ls-remote:

dan-mbp-work:~ dan$ type curl
curl is aliased to `curl --verbose -k -o/dev/null'
dan-mbp-work:~ dan$ nvm ls-remote
*   Trying 104.20.22.46...
* Connected to nodejs.org (104.20.22.46) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
* Server certificate: *.nodejs.org
* Server certificate: COMODO RSA Domain Validation Secure Server CA
* Server certificate: COMODO RSA Certification Authority
* Server certificate: AddTrust External CA Root
> GET /dist/index.tab HTTP/1.1
> Host: nodejs.org
> User-Agent: curl/7.43.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< Date: Thu, 07 Jul 2016 19:22:31 GMT
< Content-Type: text/plain
< Transfer-Encoding: chunked
< Connection: keep-alive
< Set-Cookie: __cfduid=d89d74e8ae3aad5b6eaf4a37052a6551a1467919351; expires=Fri, 07-Jul-17 19:22:31 GMT; path=/; domain=.nodejs.org; HttpOnly
< Last-Modified: Wed, 06 Jul 2016 19:37:58 GMT
< CF-Cache-Status: HIT
< Expires: Thu, 07 Jul 2016 23:22:31 GMT
< Cache-Control: public, max-age=14400
< Server: cloudflare-nginx
< CF-RAY: 2bedaa6a92cf0c89-AMS
< 
{ [892 bytes data]
* Connection #0 to host nodejs.org left intact
*   Trying 104.131.173.199...
* Connected to iojs.org (104.131.173.199) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
* Server certificate: *.nodejs.org
* Server certificate: COMODO RSA Domain Validation Secure Server CA
* Server certificate: COMODO RSA Certification Authority
* Server certificate: AddTrust External CA Root
> GET /dist/index.tab HTTP/1.1
> Host: iojs.org
> User-Agent: curl/7.43.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< Server: nginx
< Date: Thu, 07 Jul 2016 19:22:32 GMT
< Content-Type: text/plain
< Content-Length: 7395
< Last-Modified: Tue, 15 Sep 2015 09:08:02 GMT
< Connection: keep-alive
< ETag: "55f7dff2-1ce3"
< Strict-Transport-Security: max-age=63072000
< X-Frame-Options: DENY
< X-Content-Type-Options: nosniff
< Accept-Ranges: bytes
< 
{ [7395 bytes data]
* Connection #0 to host iojs.org left intact
            N/A
dan-mbp-work:~ dan$ 

I tried running:

unalias curl

But it doesn't work.

bugs installing node shell alias clobbering

All 11 comments

The proper way to set default curl options is not to alias curl - aliasing builtins is always a bad idea - but rather to use ~/.curlrc.

If you do that, instead of your alias, things will work fine.

That said, I should be using command to bypass your alias, so I'll leave this open in the meantime to fix that :-)

On second thought, I may not be able to bypass this, since curl isn't a shell builtin.

I'll look into it, but this may be a situation where overwriting curl is just going to break any tool using curl running in that shell session ¯_(ツ)_/¯

You could do:

declare curl=$(which curl)
$curl http://www.google.com/

Or:

env curl http://www.google.com/

I mean, normally I would just solve this by doing unalias curl and re-running the script in question. But that doesn't seem to work for nvm.

Ah, I'd missed that in your description. It's pretty odd that unaliasing curl didn't fix it. What's unalias curl && type curl print out? What about nvm debug?

dan-mbp-work:.nvm dan$ type curl
curl is aliased to `curl --verbose -k -o/dev/null'
dan-mbp-work:.nvm dan$ unalias curl
dan-mbp-work:.nvm dan$ type curl
curl is /usr/bin/curl
dan-mbp-work:.nvm dan$ nvm debug
nvm --version: v0.31.2
$SHELL: /bin/bash
$HOME: /Users/dan
$NVM_DIR: '$HOME/.nvm'
$PREFIX: ''
$NPM_CONFIG_PREFIX: ''
nvm current: v0.10.32
which node: $NVM_DIR/v0.10.32/bin/node
which iojs: 
which npm: $NVM_DIR/v0.10.32/bin/npm
npm config get prefix: $NVM_DIR/v0.10.32
npm root -g: $NVM_DIR/v0.10.32/lib/node_modules
dan-mbp-work:.nvm dan$ 

I just realised I don't normally have to unalias curl at all, because shell scripts don't source one's bash profile:

dan-mbp-work:tmp dan$ alias foo="echo I am foo"
dan-mbp-work:tmp dan$ foo
I am foo
dan-mbp-work:tmp dan$ cat test3.sh 
foo
dan-mbp-work:tmp dan$ bash -x test3.sh 
+ foo
test3.sh: line 1: foo: command not found
dan-mbp-work:tmp dan$ 

I think that is the key difference between an executable script and nvm (which is embedded in a user's shell environment).

The approaches in my previous comment should work if you want to fix this for others. However, I noticed that the tests rely on overriding curl in the shell so they'd need to be fixed also.

I am at a loss as to why unalias curl doesn't just work.

I also am at a loss about that.

I still recommend removing your alias entirely, and making ~/.curlrc with something like:

insecure
verbose
output=/dev/null

That will give you the same defaults but won't conflict with nvm or any other sourced shell code you run (admittedly, there's not likely to be anything)

If you edit nvm.sh to do unalias curl inside nvm_download, before curl is used, does everything work?

If you edit nvm.sh to do unalias curl inside nvm_download, before curl is used, does everything work?

No.

Shells are weird:

dan-mbp-work:~ dan$ { foo; } ; alias foo="echo hello"; { foo; }
-bash: foo: command not found
-bash: foo: command not found
dan-mbp-work:~ dan$ 

but:

dan-mbp-work:~ dan$ { echo $foo; } ; export foo=bar; { echo $foo; }

bar
dan-mbp-work:~ dan$ 

(╯°□°)╯︵ ┻━┻

Chances are, the aliasing is done in your .bashrc before nvm.sh is sourced, is that right? If so, NVM would retain the alias even if you run
unalias curl
so, try sourcing nvm.sh again after this
source ~/.nvm/nvm.sh
and NVM should now pick up the unaliased curl command.

That said, I should be using command to bypass your alias, so I'll leave this open in the meantime to fix that :-)

...

On second thought, I may not be able to bypass this, since curl isn't a shell builtin.

Why wouldn't command work? This is what help command tells:

Execute a simple command or display information about commands.

Runs COMMAND with ARGS suppressing  shell function lookup, or display
information about the specified COMMANDs.  Can be used to invoke commands
on disk when a function with the same name exists.

Hello,

I would suggest:
command curl -q ...

I ran into issues because my .curlrc had some extra lines:
-q, --disable
If used as the first parameter on the command line, the curlrc config file will not be read and used. See the -K, --config for details on the default config file search path.

Regards,
Didier

Was this page helpful?
0 / 5 - 0 ratings