Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

while sourcing nvm command works, npm and node command are not working properly #28

Closed
shangsunset opened this issue Apr 14, 2016 · 43 comments

Comments

@shangsunset
Copy link

shangsunset commented Apr 14, 2016

Hi,
So ive put the nvm function in the config.fish and installed node with nvm. however, i always get fish: Unknown command 'node' on shell startup, so is npm. they will work after i execute a nvm command though, such as nvm ls.

if nvm is already sourced, how come node wont work?

ps: tested in bash. node and npm work normally.

my config.fish:

# Fisherman config
set fisher_home ~/.local/share/fisherman
set fisher_config ~/.config/fisherman
source $fisher_home/config.fish

# Initial config file contents, which adds /usr/local/bin to the PATH environment variable.
set -g -x PATH /usr/local/bin $PATH

# Homebrew
set -g -x PATH /usr/local/sbin $PATH

# pyenv
status --is-interactive; and . (pyenv init -|psub)

function nvm
    bass source ~/.nvm/nvm.sh ';' nvm $argv
end



# Will eliminate the Fish welcome message that appears by default
set -g -x fish_greeting ''

@ghost
Copy link

ghost commented Apr 15, 2016

@shangsunset For starters, I think the correct function is:

function nvm
     bass source ~/.nvm/nvm.sh --no-use ';' nvm $argv
end

@edc
Copy link
Owner

edc commented Apr 15, 2016

@shangsunset let me know if what @bucaran suggested works for you.

@shangsunset
Copy link
Author

unfortunately, it didnt work.

@ghost
Copy link

ghost commented Apr 16, 2016

@shangsunset

Why the following?

set -g -x PATH /usr/local/bin $PATH

isn't /usr/local/bin/ supposed to be in PATH by default?

And one more thing, neither node or npm are in your $PATH when the sessions starts. So, try

printf "%s\n" $PATH

@shangsunset
Copy link
Author

Hey @bucaran, I deleted set -g -x PATH /usr/local/bin $PATH and this is the output from running printf "%s\n" $PATH:

/Users/shangsunset/.pyenv/shims
/usr/local/sbin
/Users/shangsunset/.nvm/versions/node/v5.10.1/bin
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin

@ghost
Copy link

ghost commented Apr 16, 2016

/Users/shangsunset/.nvm/versions/node/v5.10.1/bin shows first than /usr/local/bin, which makes sense, but what's inside the nvm path?

ls -la /Users/shangsunset/.nvm/versions/node/v5.10.1/bin

@shangsunset
Copy link
Author

total 46224
drwxr-xr-x   4 shangsunset  staff       136 Apr  5 17:47 .
drwxr-xr-x  10 shangsunset  staff       340 Apr 15 09:34 ..
-rwxr-xr-x   1 shangsunset  staff  23661896 Apr  5 17:47 node
lrwxr-xr-x   1 shangsunset  staff        38 Apr  5 17:47 npm -> ../lib/node_modules/npm/bin/npm-cli.js

@ghost
Copy link

ghost commented Apr 16, 2016

And you are saying that when you run, npm or node, you get a "command not found" error?

@shangsunset
Copy link
Author

yes

@ghost
Copy link

ghost commented Apr 16, 2016

And what happens if you do

/Users/shangsunset/.nvm/versions/node/v5.10.1/bin/node -v

@ghost
Copy link

ghost commented Apr 16, 2016

Also, do you have a .bash_profile file in your $HOME directory? and if you do, what is its contents?

@shangsunset
Copy link
Author

shangsunset commented Apr 16, 2016

shangsunset@Yeshens-MBP ~> /Users/shangsunset/.nvm/versions/node/v5.10.1/bin/node -v
v5.10.1
shangsunset@Yeshens-MBP ~> cat .bash_profile
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
shangsunset@Yeshens-MBP ~>

does .bash_profile still matter if we are using fish?

@ghost
Copy link

ghost commented Apr 16, 2016

Right, it does not matter in fish, but nvm is a bash script and I wanted to see if you were defining any aliases.

If /Users/shangsunset/.nvm/versions/node/v5.10.1/bin/node works, how come node, does not?

Try this:

set -gx PATH /Users/shangsunset/.nvm/versions/node/v5.10.1/bin

and run node again. If that does not work, comment out your .bash_profile and try again. I don't know how nvm works internally, so that's just a desperate measure.

@shangsunset
Copy link
Author

mmm that works

@ghost
Copy link

ghost commented Apr 16, 2016

Okay, can you check what's inside:

/Users/shangsunset/.pyenv/shims
/usr/local/sbin

@shangsunset
Copy link
Author

shangsunset@Yeshens-MBP ~> ls -la /Users/shangsunset/.pyenv/shims
total 0
drwxr-xr-x  2 shangsunset  staff   68 Apr 16 00:31 .
drwxr-xr-x  4 shangsunset  staff  136 Apr 11 10:50 ..
shangsunset@Yeshens-MBP ~> ls -la /usr/local/sbin
total 16
drwxr-xr-x   4 shangsunset  admin  136 Apr 12 09:04 .
drwxrwxr-x  20 shangsunset  admin  680 Apr 12 10:07 ..
lrwxr-xr-x   1 shangsunset  admin   35 Apr 12 09:04 php-fpm -> ../Cellar/php56/5.6.20/sbin/php-fpm
lrwxr-xr-x   1 shangsunset  admin   37 Apr 12 09:04 php56-fpm -> ../Cellar/php56/5.6.20/sbin/php56-fpm
shangsunset@Yeshens-MBP ~>

@ghost
Copy link

ghost commented Apr 16, 2016

Well, that looks alright, I guess.

Comment out all of your config.fish, and just leave this

set fisher_home ~/.local/share/fisherman
set fisher_config ~/.config/fisherman
source $fisher_home/config.fish

function nvm
   bass source ~/.nvm/nvm.sh --no-use ';' nvm $argv
end

Then reload the shell and try using nvm as you are used to again.

@shangsunset
Copy link
Author

shangsunset commented Apr 16, 2016

still getting fish: Unknown command 'node' :(
so weird. i can use nvm to install node but node is unknown...

@ghost
Copy link

ghost commented Apr 16, 2016

And if you modify your PATH like this?

/Users/shangsunset/.nvm/versions/node/v5.10.1/bin
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin

@shangsunset
Copy link
Author

yea node works with /Users/shangsunset/.nvm/versions/node/v5.10.1/bin in PATH

@ghost
Copy link

ghost commented Apr 16, 2016

So, the problem is solved. What is the issue again?

@shangsunset
Copy link
Author

so i need to put set -gx PATH /Users/shangsunset/.nvm/versions/node/v5.10.1/bin $PATH in my config.fish?

@ghost ghost mentioned this issue Apr 16, 2016
@ghost
Copy link

ghost commented Apr 16, 2016

@shangsunset

Nope, that's exactly nvm's job. You need to do is run nvm or nvm use foo when you restart your shell / cd into a path with a .nvmrc, etc., everytime.

Because nvm mods in your PATH will not be persisted across sessions AFIK.

I think you were just using nvm incorrectly, so not your fault, I was confused about this too.

@shangsunset
Copy link
Author

I need to run nvm every time when i use node or npm from now on? That doesnt sound very ideal...
I wonder why I didnt have to run nvm every time when i was using zsh or omf/plugin-nvm. hmmmm...

@ghost
Copy link

ghost commented Apr 17, 2016

@shangsunset

  • If you use nvm like a function, you need to run it every time
  • if you don't want to run it every time, you can source nvm in your config.fish or create a snippet that does it for you.

I wonder why I didnt have to run nvm every time when i was using zsh or omf/plugin-nvm. hmmmm...

Well, that's because they either source nvm or call the nvm function for you on shell startup.

Related: nvm-sh/nvm#303 (comment)

@ghost
Copy link

ghost commented Apr 17, 2016

@shangsunset

Just rm ~/.config/functions/config.fish, and create a new config.fish with this:

set fisher_home ~/.local/share/fisherman
set fisher_config ~/.config/fisherman
source $fisher_home/config.fish

### add your other configuration here

function nvm
     bass source ~/.nvm/nvm.sh --no-use ';' nvm $argv
end

nvm  ### call nvm HERE so you don't have to call it every time

@shangsunset
Copy link
Author

@bucaran

Really appreciate your help and patience. However, even though i deleted my existing config.fish and created a new one with what you provided, node and npm are still not available upon shell start. unless i run nvm use node.

@ghost
Copy link

ghost commented Apr 19, 2016

@shangsunset I think you could make your life a ton easier if you switched to tj/n, at least just temporarily until you figure out how nvm works.

https://github.com/tj/n

If you really want to use nvm, though, I advise you to read their documentation thoroughly and learn how to use it instead of depending on plugins first.

Also, please read the "official" fish tutorial. Please take no offence, as I could be wrong, but given your responses, it looks as if you still don't really understand the difference between calling a function, running code on shell startup, etc.

@shangsunset
Copy link
Author

ok thanks.

@ghost
Copy link

ghost commented Apr 27, 2016

@shangsunset https://github.com/fisherman/nvm

@ljharb
Copy link

ljharb commented Apr 27, 2016

Please do not steal other people's project names.

@ghost
Copy link

ghost commented Apr 27, 2016

@ljharb Dude, you are completely misinterpreting my plugin. The purpose of fisherman/nvm is to serve as a bridge between creationix/nvm and the missing nvm solution in fish.

@ljharb
Copy link

ljharb commented Apr 27, 2016

I did - I asked you politely to change it. You said "No". call it nvm-fish if you like - but not "nvm". That's confusing for users, and makes googling harder, even if it wasn't rude and potentially an implicit trademark violation.

@ghost
Copy link

ghost commented Apr 27, 2016

People that use fisherman know that stuff inside the org, are all plugins for fish, kind of like ohmyfish and similar projects. I wouldn't say it's confusing.

@ljharb
Copy link

ljharb commented Apr 27, 2016

You were politely asked by a project whose name you copied to change it. Whether you agree that it's confusing is irrelevant - it's not cool, under any circumstances.

@ghost
Copy link

ghost commented Apr 27, 2016

First, you were not polite, you were not rude either, but you were definitely very hostile. You even called me an "asshole". Why should I accept that? People on the internet are very confrontational when facing a white message box. You wouldn't call me an asshole to my face.

Second, I worked hard on this thing, not that it matters, but I put it there because a lot of people have asked for an nvm in fish for like years and there just wasn't one. Sure, there are wrappers, but it's just not the same. I am calling the project nvm for a simple reason, people migrating from bash to fish that have used creationix/nvm before, are likely to search for "nvm in fish" when they realize creationix/nvm does not work in fish.

@ljharb
Copy link

ljharb commented Apr 27, 2016

so call it "nvm in fish". I insulted you after you posted a very rude one-word answer "No", and after you called me "bro" (which is also rude; you don't know me) and told me to "chill".

I'm glad you worked hard on it, and I hope your project is successful - but it should be successful under its own name, not by stealing the name of something else. If you don't change your name, and your project attains any notoriety, it will forever live under the shadow of that - I won't be the only one you hear it from. Why not just change it?

@ghost
Copy link

ghost commented Apr 27, 2016

Well, that's a touching way to put it. There you go: https://github.com/fisherman/nbm ;)

And, I said "dude". From there to asshole it's quite a big jump.

EDIT: Went with https://github.com/fisherman/fish-nvm

EDIT 2: Went with https://github.com/fisherman/fin lol

@ljharb
Copy link

ljharb commented Apr 27, 2016

Thanks, much obliged.

@ghost
Copy link

ghost commented Apr 27, 2016

@ljharb See edit. If that's okay with you I'd like to add it to the list of alternatives in your README.

@ljharb
Copy link

ljharb commented Apr 27, 2016

@bucaran thank you, that sounds great. Please feel free to send a PR.

@FabioAntunes
Copy link
Contributor

@bucaran fish-nvm was way better than fin, it's very funny naming stuff after fishes and stuff related to them, but that makes googling hard as hell.

If I want a nvm for fish I will search for that on google, not fin. If I want to run bash script on my fish shell I will search for fish bash wrapper or fish bash runner, not bass.

@shangsunset You can solve your problem sourcing nvm every time you open a new shell, this will add a minor delay, but at least it works, just put this line on your config file at ~/.config/fish/config.fish

bass source ~/.nvm/nvm.sh >/dev/null ^&1

@ghost
Copy link

ghost commented Apr 27, 2016

@FabioAntunes Which is why I named it nvm in the first place, but then ljharb was right, I can't just name my project after creationix/nvm like that, so I changed it to fin.

Now, bear in mind that fin is not a drop-in replacement for nvm nor it requires nvm as a dependency. It's a standalone node version manager written in fish.

If I want a nvm for fish I will search for that on google, not fin. If I want to run bash script on my fish shell I will search for fish bash wrapper or fish bash runner, not bass.

I couldn't agree more, and just like fisherman, SEO will be hard to do. Now, on the other hand, those who find it will appreciate it like the hidden gem it is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants