nvm icon indicating copy to clipboard operation
nvm copied to clipboard

No proxy option in nvm install script

Open typhoe opened this issue 2 years ago • 14 comments

Operating system and version:

NAME="Ubuntu" VERSION="20.04.5 LTS (Focal Fossa)"

nvm debug output:

Trying to install latest = 0.39.3

nvm ls output:

none ...Trying to install

How did you install nvm?

following the readme

What steps did you perform?

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash

What happened?

error, I'm behind an entreprise proxy... no option to pass a proxy in install script

What did you expect to happen?

Well, I expected to be able to install nvm

Is there anything in any of your profile files that modifies the PATH?

no

Improved install command that worked for me (using proxy)

I propose a simple solution to correct the install script to work with proxy (only correcting curl and git, not wget... could be added)

export Proxy=http://my_enterprise_proxy:3128
curl --proxy $Proxy -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh |sed -e 's/git /git -c "http.proxy=$Proxy" /g' -e 's/curl /curl --proxy $Proxy /g' |bash

typhoe avatar Jan 12 '23 14:01 typhoe

To use nvm, I also needed to add $Proxy var to the .nvm/nvm.sh script on line 124 in nvm_download() function

    curl --fail ${CURL_COMPRESSED_FLAG:-} -q "$@"
    curl --proxy $Proxy --fail ${CURL_COMPRESSED_FLAG:-} -q "$@"

typhoe avatar Jan 12 '23 14:01 typhoe

If you’re behind a proxy then installing node won’t work either, as you discovered. Why does your enterprise proxy block outbound requests?

ljharb avatar Jan 12 '23 16:01 ljharb

No, it works with the change I posted. I managed to install nodejs 14/16/18/19 and use them without any problem (after declaring my proxy of course when needed)

The proxy my enterprise uses is a filtering one.... only dns declared are allowed.

typhoe avatar Jan 12 '23 17:01 typhoe

And there’s no way you could get them to allow github and nodejs.org?

ljharb avatar Jan 12 '23 17:01 ljharb

I did, it works now BUT I have to tell curl and git to use the proxy.... thus the issue I posted There's no option in nvm to tell it to use a proxy right now...

typhoe avatar Jan 12 '23 17:01 typhoe

that's not what i mean - i mean, tell your company to be less restrictive in its proxy configuration.

Separately, could you use a SOCKS proxy so it was transparent to tooling?

I agree there's no option in nvm to use a proxy, and it explicitly ignores curlrc which might be configured to use one, but that's somewhat by design.

ljharb avatar Jan 12 '23 17:01 ljharb

I'd really like if telling my company that was a possibility but that's the problem... most company put these type of restriction with the aim to limit access to external network, so no, that's not an option sadly... I don't want to use a sock proxy because depending of what resource I need to access, I'm using various proxy or vpn depending of the use case.

But if you look at what I did, getting nvm to work with proxy seems pretty easy:

  1. for the install part, we'd simply need to tell curl to use the proxy whenever we want to download something (thus the sed part in the command line to add --proxy $Proxy everywhere... even when it's not needed like invoking curl --version) and same for git to clone nvm repo (-c http.proxy=$Proxy) What would be nice is to set an env var and then in the install script, it would be possible to define additional options for curl and git to use. Assuming NVM_PROXY the proxy we want nvm to use and CURL_PROXY / GIT_PROXY the option we would pass to these command:
if [ ! -z ${NVM_PROXY+x} ] ;then
  CURL_PROXY="--proxy ${NVM_PROXY}"
  GIT_PROXY="-c http.proxy=${NVM_PROXY}"
fi
  1. for the nvm.sh script, I only needed to change the curl command in the nvm_download function to get nvm working perfectly But I guess there may be something to let it also update itself (eg. git pull) somewhere that I missed?

typhoe avatar Jan 12 '23 23:01 typhoe

No, nvm doesn't update itself, you update it by rerunning the install script.

I agree it'd be a relatively straightforward addition to have nvm respect a proxy setting, but there's a few complications - for one, nvm works with either curl or wget, so we'd have to make sure the proxy argument was equally configurable - but more importantly, it'd be a huge source of bugs, and since you're the first person i'm aware of to request it in over a decade, we might want to wait until there's higher demand for it.

ljharb avatar Jan 13 '23 00:01 ljharb

Ok, I understand your choice. And as it was quite easy for me to "add" proxy option by simply using a sed command, I'll keep doing that for now. Anyway, thank you very much for this tool that helps a lot and for listening to my request! :+1:

typhoe avatar Jan 13 '23 00:01 typhoe

Operating system and version:

NAME="Ubuntu" VERSION="20.04.5 LTS (Focal Fossa)"

nvm debug output:

nvm ls output:

How did you install nvm?

following the readme

What steps did you perform?

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash

What happened?

error, I'm behind an entreprise proxy... no option to pass a proxy in install script

What did you expect to happen?

Well, I expected to be able to install nvm

Is there anything in any of your profile files that modifies the PATH?

no

Improved install command that worked for me (using proxy)

I propose a simple solution to correct the install script to work with proxy (only correcting curl and git, not wget... could be added)

export Proxy=http://my_enterprise_proxy:3128
curl --proxy $Proxy -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh |sed -e 's/git /git -c "http.proxy=$Proxy" /g' -e 's/curl /curl --proxy $Proxy /g' |bash

string

ZackaryJacobthereal avatar Jan 14 '23 13:01 ZackaryJacobthereal

string

@ZackaryJacobthereal I'm not sure I understand your comment.... ???

typhoe avatar Jan 15 '23 11:01 typhoe

To use nvm, I also needed to add $Proxy var to the .nvm/nvm.sh script on line 124 in nvm_download() function

    curl --fail ${CURL_COMPRESSED_FLAG:-} -q "$@"
    curl --proxy $Proxy --fail ${CURL_COMPRESSED_FLAG:-} -q "$@"

Many thanks for this one. It works for me. I have to emphasize that my company has those kind of proxy restrictions as well. I upvote a proxy support for nvm as well. Thanks in advance rivermanbw

rivermanbw avatar Apr 25 '23 10:04 rivermanbw

Related: #963, #3366.

ljharb avatar Jun 10 '24 06:06 ljharb

Related: #963, #3366.

Reading the replies to #963 my need of a proxy could also be resolved by setting the https_proxy linux env variable, but I would have to set it each time before invoking nvm. I have to use various proxy and the default proxy set in https_proxy is not the one allowing me to use nvm... Thus for me the need for a specific NVM_Proxy setting, it's far more convenient to use.

typhoe avatar Jun 10 '24 08:06 typhoe