nvm
nvm copied to clipboard
HEAD detached at FETCH_HEAD
Operating system and version:
- Windows 10
- WSL2 with Ubuntu 20.04.2
How did you install nvm
?
From WSL Ubuntu terminal
sudo apt update
sudo apt install build-essential checkinstall libssl-dev
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.38.0/install.sh | bash
What happened?
- nvm repo is cloned into ~/.nvm
- Then I get a message "HEAD detached at FETCH_HEAD"
- No interaction possible with the terminal at that stage
What did you expect to happen?
- installation of nvm should happen
Is there anything in any of your profile files that modifies the PATH
?
I use Oh-my-zsh with powerlevel10k theme
If you are having installation issues, or getting "N/A", what does curl -I --compressed -v https://nodejs.org/dist/
print out?
* Trying 104.20.22.46:443...
* TCP_NODELAY set
* Connected to nodejs.org (104.20.22.46) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: /etc/ssl/certs/ca-certificates.crt
CApath: /etc/ssl/certs
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
* TLSv1.3 (IN), TLS handshake, Finished (20):
* TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.3 (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
* ALPN, server accepted to use h2
* Server certificate:
* subject: OU=Domain Control Validated; OU=PositiveSSL Wildcard; CN=*.nodejs.org
* start date: Oct 21 00:00:00 2019 GMT
* expire date: Jan 18 23:59:59 2022 GMT
* subjectAltName: host "nodejs.org" matched cert's "nodejs.org"
* issuer: C=GB; ST=Greater Manchester; L=Salford; O=Sectigo Limited; CN=Sectigo RSA Domain Validation Secure Server CA
* SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x557958f75820)
> HEAD /dist/ HTTP/2
> Host: nodejs.org
> user-agent: curl/7.68.0
> accept: */*
> accept-encoding: deflate, gzip, br
>
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* old SSL session ID is stale, removing
* Connection state changed (MAX_CONCURRENT_STREAMS == 256)!
< HTTP/2 200
HTTP/2 200
< date: Thu, 15 Apr 2021 07:36:02 GMT
date: Thu, 15 Apr 2021 07:36:02 GMT
< content-type: text/html
content-type: text/html
< set-cookie: __cfduid=d5508647aedc3c2383cf7d2b0cf14b8111618472162; expires=Sat, 15-May-21 07:36:02 GMT; path=/; domain=.nodejs.org; HttpOnly; SameSite=Lax
set-cookie: __cfduid=d5508647aedc3c2383cf7d2b0cf14b8111618472162; expires=Sat, 15-May-21 07:36:02 GMT; path=/; domain=.nodejs.org; HttpOnly; SameSite=Lax
< cache-control: max-age=14400
cache-control: max-age=14400
< cf-cache-status: HIT
cf-cache-status: HIT
< age: 1389
age: 1389
< cf-request-id: 09760e6e3c0000016a5c905000000001
cf-request-id: 09760e6e3c0000016a5c905000000001
< expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
< vary: Accept-Encoding
vary: Accept-Encoding
< server: cloudflare
server: cloudflare
< cf-ray: 64038029fb08016a-SIN
cf-ray: 64038029fb08016a-SIN
< content-encoding: br
content-encoding: br
<
* Connection #0 to host nodejs.org left intact
What version of git do you have?
I have Git version 2.25.1
Note that, as workaround I did the manual installation and it worked without issue:
sudo apt update
sudo apt install build-essential checkinstall libssl-dev
git clone https://github.com/nvm-sh/nvm.git .nvm
git checkout v0.38.0
# Add the following in ~/.zshrc
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
source ~/.zshrc
This may have been caused by #2401; i think it could be fixed by adding -c advice.detachedHead=false
to every git
command in install.sh
.
I have tried on Windows 10 and WSL2:
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 14926 100 14926 0 0 70739 0 --:--:-- --:--:-- --:--:-- 71076
=> Downloading nvm from git to '/home/nmarghetti/.nvm'
=> Cloning into '/home/nmarghetti/.nvm'...
remote: Enumerating objects: 345, done.
remote: Counting objects: 100% (345/345), done.
remote: Compressing objects: 100% (292/292), done.
remote: Total 345 (delta 38), reused 170 (delta 28), pack-reused 0
Receiving objects: 100% (345/345), 194.58 KiB | 2.53 MiB/s, done.
Resolving deltas: 100% (38/38), done.
* (HEAD detached at FETCH_HEAD)
master
=> Compressing and cleaning up git repository
=> Appending nvm source string to /home/nmarghetti/.bashrc
=> Appending bash_completion source string to /home/nmarghetti/.bashrc
=> Close and reopen your terminal to start using nvm or run the following to use it now:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
I indeed get the HEAD detached at FETCH_HEAD
information but it is normal.
Then I sourced ~/.bashrc and nvm is available.
All works fine for me.
However I see that you used repository from creationix, is there any change in there ? Also it seems you are using zsh, do you have the same problem with bash ?
(That repo is this one, so it should be redirecting transparently)
on WSL2, using bash, using nvm-sh repo, I still got the same behavior:
my terminal displays
* (HEAD detached at v0.38.0)
master
(END)
and get stuck there. no way to get back the hand or do anything
This also happens on clean install of macOS Big Sur. Not only on Windows/Ubuntu.
@Legoless what is "this"? that the text "HEAD detached" appears is not necessarily a problem.
@ljharb I think it is a problem, because I stuck there forever on macOS Big Sur.
@megataps can you provide your exact output?

@ljharb Please see on the attached image.
It takes forever like that. I have to "Control + C" to stop it. Then I checked nvm -v
but the result show that It did not install.
@megataps what version of git are you using? Which shell?
@Legoless what is "this"? that the text "HEAD detached" appears is not necessarily a problem.
Exactly the same as @megataps posted. Just stuck there even Ctrl + C
didn't work for me, had to kill the session. nvm
was not installed, so I had to do manual installation. Git version: 2.30.1 (Apple Git-130)
and latest Oh-My-ZSH.
same for me. Using ubuntu 21.04 and zsh.
Can all of you stuck installing v0.38.0 try running the install script, but pointed at v0.37.2? That would help me narrow it down.
Same promblem for me. Using ubuntu 18.04
Instead of posting "same problem", can you please try https://github.com/nvm-sh/nvm/issues/2486#issuecomment-832974597 and report results?
I have te same problem on Mac and tried installing with version 0.37.2.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
It has the same effect.
@rondgrt thanks - could you try a few older versions? It will be very helpful to pinpoint when it started failing.
Ok, did some more tests and it seems to be that this does NOT happen at version 0.37.2. In my previous test i did not remove the .nvm directory. And then the same problem occurred.
With a non existing .nvm directory version 0.38.0 shows the problem, and version 0.37.2 installs correct.
I hope this will help.
Strange enough after succesfull instal version 0.37.2 the nvm -v shows me the 0.38.0 version !?!
@rondgrt you'd need to nvm deactivate
to completely remove it from the shell first.
cc @nmarghetti
Hi,
TL;DR
Had the same "HEAD detached at FETCH_HEAD" problem with this conf: MacBook Pro, M1, 11.2.3 (Mac Os BigSur) + curl installation of nvm v0.38.0.
Removing v0.38.0 and installing v0.37.2, then switching to a X64
based architecture before installing a node version made the trick.
Now, to give more details :
On a new Mac, I installed nvm v0.38.0 (with curl). Nvm seemingly installed correctly, but my work environnement became very instable. It could take up to 10mn to install a yarn project when it usually takes less than 2. Some other projects simply wouldn't build (memory leak, indefinitely load...).
I try uninstalling nvm and reinstalling it again. This time, got the "HEAD detached at FETCH_HEAD" message. Tried to install nvm v0.37.2 instead as proposed by @ljharb, no more error. However, most of my NodeJs project were once again unusable.
I finally came across this post https://stackoverflow.com/a/66380037 explaining how node v14 and under were not well supported on new Mac M1 (Apple Sillicon and arm64
architecture).
Before installing an old NodeJs version, I had to make sure NodeJs was running in x64
mode :
$arch -x86_64 zsh
$nvm install 12.13.0
Hope this can be helpful.
node does not support M1 macs at all prior to v16, unless you're in rosetta.
https://github.com/nvm-sh/nvm/issues/2486#issuecomment-840553869 Same problem :
WSL2 (Debian 10), W10 21H1, Git 2.20, nvm 0.38
sudo su
resolve the problem for me.
Has anyone found a solution to this issue? I'm still unable to install NVM on any of my machines (2 Windows WSL machines, and one M1 Mac)
If you look on top of the issue, you can see that a manual installation (clone git repo + edit your bashrc) works fine
hi all, I also encounter this problem and here is my solution
I just run the following command and then it works.
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
to make it permant
add top command to .zshrc if you are using ZSH like me
The problem I guess why :
I check echo $NVM_DIR
and find it output nothing.
And I think the zsh execution is boken when meet this problem and the following zsh not worked as it suppose to do.
Hope it helps
hi all, I also encounter this problem and here is my solution
I just run the following command and then it works.
export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
to make it permant
add top command to .zshrc if you are using ZSH like me
The problem I guess why : I check
echo $NVM_DIR
and find it output nothing. And I think the zsh execution is boken when meet this problem and the following zsh not worked as it suppose to do.Hope it helps
Thx, it works for me in wsl2 ubuntu
Just type in q and you'll be able to come out of this non-interactable page and the rest of the installation gets done.
hi all, I also encounter this problem and here is my solution
I just run the following command and then it works.
export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
to make it permant
add top command to .zshrc if you are using ZSH like me
The problem I guess why : I check
echo $NVM_DIR
and find it output nothing. And I think the zsh execution is boken when meet this problem and the following zsh not worked as it suppose to do.Hope it helps
How do I "add the top command to zsh"?
@andrejarboe to .zshrc
- a file inside your home directory.
Just type in q and you'll be able to come out of this non-interactable page and the rest of the installation gets done.
this works!
@bestiptx99 do you think we'd be able to either fix the install script to avoid the need for this, or, detect when it's happening and print a message telling the user to hit "q"?
Just type in q and you'll be able to come out of this non-interactable page and the rest of the installation gets done.
@bestiptx99 do you think we'd be able to either fix the install script to avoid the need for this, or, detect when it's happening and print a message telling the user to hit "q"?
This "looked" like it worked but still would not enable use of NVM. Purged global NPM packages, purged APT-installed NPM as well as nodejs and dependencies, then installed NVM 0.38.0 using manual method and it seems to be working alright. Still need to install npm and nodejs, hopefully it all works ok. edit: I'm on Linux Mint 20.1 (Ubuntu 20.01 LTS) last edit: installing latest npm and node.js worked perfectly. nvm rocks
Well this seems to be a little messed up.
The workaround is to do the following:
cd ~
git clone https://github.com/nvm-sh/nvm.git .nvm
cd .nvm
git switch -c v0.38.0
That will:
Change your terminal to the current user's home directory
Clone the NVM repository to your machine
Change your terminal to the NVM install directory
Change the NVM version to 38 (not strictly necessary)
Once NVM is installed, you also need to export the necessary links, so that your terminal knows it exists. To do that (for ZSH), type:
cat <<EOT >> ~/.zshrc
# NVM Installation
export NVM_DIR="\$([ -z "\${XDG_CONFIG_HOME-}" ] && printf %s "\${HOME}/.nvm" || printf %s "\${XDG_CONFIG_HOME}/nvm")"
[ -s "\$NVM_DIR/nvm.sh" ] && \. "\$NVM_DIR/nvm.sh" # This loads nvm
[ -s "\$NVM_DIR/bash_completion" ] && \. "\$NVM_DIR/bash_completion" # This loads nvm bash_completion
EOT
This will add lines 2 to 6 to the end of the .zshrc
file. If you're using bash, change the above reference to .bashrc
instead.
Then to get the change to work in your current terminal (without having to exit and reload the window), run the following:
. ~/.zshrc
Again, changing to .bashrc
, if necessary.
@flatline-studios your steps are basically exactly the "manual git install" steps, which is fine.
I still can't figure out how to reproduce the issue; it seems to be happening for a very small number of users on very different machines and OS's.
Is there any chance that all of you have a password (or other) prompt on SSH connections? What happens if you git clone [email protected]:nvm-sh/nvm.git
instead of the HTTPs URL? (SSH cloning is almost always better than HTTPs cloning anyways)
@flatline-studios your steps are basically exactly the "manual git install" steps, which is fine.
I still can't figure out how to reproduce the issue; it seems to be happening for a very small number of users on very different machines and OS's.
Is there any chance that all of you have a password (or other) prompt on SSH connections? What happens if you
git clone [email protected]:nvm-sh/nvm.git
instead of the HTTPs URL? (SSH cloning is almost always better than HTTPs cloning anyways)
this is what happens when I try that:
~$ git clone [email protected]:nvm-sh/nvm.git
Cloning into 'nvm'...
The authenticity of host 'github.com (140.82.114.4)' can't be established.
RSA key fingerprint is SHA256:[redacted].
Are you sure you want to continue connecting (yes/no/[fingerprint])? y
Please type 'yes', 'no' or the fingerprint: yes
Warning: Permanently added 'github.com,140.82.114.4' (RSA) to the list of known hosts.
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I don't have SSH setup for git. HTTPs cloning works fine of course. I use token for git operations if that makes a difference.
I ran into this trying to install nvm from an automated Ansible playbook, so "hitting q" is not an acceptable workaround. Also, manually adding the config block to .zshrc
doesn't solve anything as this happens during the initial curl
command and breaks the workflow. My current workaround is to pin installation at 0.37.2, and I would really appreciate a proper fix.
@bmoeskau as soon as i can properly reproduce it, i'll be able to properly fix it.
I dug into this today and here is what I found. The issue was introduced in the January 13 changes to install.sh
, specifically around lines 131-157 in the diff. It will be helpful to follow along in that diff as you read below.
I have converted the relevant original commands from that block into the parsed equivalents of what gets executed using version 0.38.0, so that it can be easily reproduced in the terminal by hand. I ran cd .nvm
after cloning below just for the convenience of omitting the redundant --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR"
portion of each original command, and for being able to easily check branch status, etc.
0.37.2 logic
Start at a scratch root folder and run the following:
Command | Output
git -c advice.detachedHead=false clone https://github.com/nvm-sh/nvm.git -b v0.38.0 --depth=1 .nvm
| n/a
| cd .nvm
| git status = "Not currently on any branch."
| git -c advice.detachedHead=false checkout -f --quiet v0.38.0
| git status = "Not currently on any branch."
| git show-ref refs/heads/master
| (blank output -- the only current ref is refs/tags/v0.38.0)
| git branch --quiet 2>/dev/null;
| (this command is actually skipped, since there was no master ref)
| |
At this point, everything completes as expected.
0.38.0 logic
Return to the scratch root folder and run the following (run rm -rf <root>/.nvm
to reset):
Command | Output
git clone https://github.com/nvm-sh/nvm.git --depth=1 .nvm
| n/a
| cd .nvm
| git status = "On branch master. Your branch is up to date with 'origin/master'."
| git fetch origin tag v0.38.0 --depth=1
| git status = "On branch master. Your branch is up to date with 'origin/master'."
| git -c advice.detachedHead=false checkout -f --quiet FETCH_HEAD
| git status = "HEAD detached at FETCH_HEAD"
| git show-ref refs/heads/master
| output = "5b77f7d0233b5be54484943c8976ad403308e4a6 refs/heads/master"
| git branch --quiet 2>/dev/null;
|
| |
I'm not sure what the proper solution is, but I will note that the code that does git branch --quiet 2>/dev/null;
actually seems incorrect, and was possibly a bug that wasn't getting triggered until the preceding code was changed. Since there is no branch name, that command is equivalent to running git branch --list
which is why we're ending up in that branch list view. If the intention is to actually create a new branch based on FETCH_HEAD the command should include a branch name like git branch foo --quiet
. However, I'm unclear on what the purpose of creating a branch there is to begin with.
I was able to "fix" this by essentially reverting the method used to clone the repo. I replaced
git clone https://github.com/nvm-sh/nvm.git --depth=1 .nvm
with the original
git -c advice.detachedHead=false clone https://github.com/nvm-sh/nvm.git -b v0.38.0 --depth=1 .nvm
and it worked again. But again, that might just be reverting to skipping a hidden bug. If the newer method of cloning and using the FETCH_HEAD
is the desired approach, then I think either creating the branch correctly, or possibly just skipping that entire bit of branch logic, is the correct solution. I would be happy to submit a PR with some guidance regarding what the expected behavior is here.
Thanks, and I hope this helps.
Thanks, that's very thorough.
cc @nmarghetti on whether applying the fix mentioned above is workable; if so, let's do it, and @bmoeskau, if the git branch
is dead code, then let's remove that separately.
If that fix is not workable, then it'd be great if someone wanted to dive in and help figure out what the right approach should be here.
I had the same problem on the new MacBook Pro M1 Pro chip and was able to make nvm work by quitting iterm and restarting the terminal instance with . ~/.nvm/nvm.sh
like it's said in the docs Troubleshooting on macOS
section.
So maybe nvm install good and there is bug in the initializing process.
I had the same problem on the new MacBook Pro M1 Pro chip and was able to make nvm work by quitting iterm and restarting the terminal instance with
. ~/.nvm/nvm.sh
like it's said in the docsTroubleshooting on macOS
section. So maybe nvm install good and there is bug in the initializing process.
EDIT: It wasn't working after relaunching the terminal. I had to do install nvm manually !
Had no problems installing 12.22.7 on an M1, just had to press 'Q' on the detached HEAD thing.
Had no problems installing 12.22.7 on an M1, just had to press 'Q' on the detached HEAD thing.
i think the problem is that it doesn't automatically quit the installation, and don't add the PATH after as it should, i guess that's why i had to do it manually.
Seems like there have been no takers on this yet. It looks like @nmarghetti was the committer for the diff I outlined above. Any chance they are available to weigh in on what the proper fix would be at this point?
So I had the same issue when I installed it with curl but I used the wget instead and it seemed to work... try checking out this video
https://www.youtube.com/watch?v=3nRQJ4vnZdI
Just type in q and you'll be able to come out of this non-interactable page and the rest of the installation gets done.
Can we pin this?
@JimmyBringus no, that’s not a feature GitHub has.