Skip to content

No proxy option in nvm install script #3003

Open

Description

@typhoe

Operating system and version:

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

nvm debug output:

Details
Trying to install latest = 0.39.3

nvm ls output:

Details
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

Activity

  1. typhoe commented on Jan 12, 2023

    @typhoe
    Author

    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 "$@"
  2. ljharb commented on Jan 12, 2023

    @ljharb
    Member

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

  3. typhoe commented on Jan 12, 2023

    @typhoe
    Author

    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.

  4. ljharb commented on Jan 12, 2023

    @ljharb
    Member

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

  5. typhoe commented on Jan 12, 2023

    @typhoe
    Author

    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...

  6. ljharb commented on Jan 12, 2023

    @ljharb
    Member

    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.

  7. typhoe commented on Jan 12, 2023

    @typhoe
    Author

    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?
  8. ljharb commented on Jan 13, 2023

    @ljharb
    Member

    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.

  9. typhoe commented on Jan 13, 2023

    @typhoe
    Author

    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! 👍

  10. ZackaryJacobthereal commented on Jan 14, 2023

    @ZackaryJacobthereal
  11. typhoe commented on Jan 15, 2023

    @typhoe
    Author
  12. rivermanbw commented on Apr 25, 2023

    @rivermanbw

    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

  13. ljharb commented on Jun 10, 2024

    @ljharb
    Member

    Related: #963, #3366.

  14. typhoe commented on Jun 10, 2024

    @typhoe
    Author

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions