How to reset the $PATH? - node.js

I confess, I very don't know what I'm talking about.
This morning I wanted to install Javascripting (to learn javascript) on my Mac, so I watch a video to do it:
I downloaded node.js and I installed it;
after that I opened the terminal and I type: npm install -g javascripting and here I've got some errors. I tried to search the solution but I think I created a big problem:
Basically I modified the $PATH several times and now the situation is this.
If I run echo PATH it displays
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
I wanted to clean it all so I tried to type:
brew uninstall --force node
but the terminal says:
zsh: command not found: brew
I can't do anything.
Please, someone help me :(

If you just want to clear this environment variable, just do 'unset PATH'.
But, be aware that PATH is used by a shell (i.e. bash, ksh, zsh...) to look for programs in these directories. clearing it has side effects.
The 'brew' program is somewhere, to find it, you could use the following command :
find / -name 'brew' -print
It can take a little while to find it.
Either use that found path, or add the directory where that program is found to the PATH variable, as in
PATH=$PATH:/location_of_brew_program; export PATH

Related

Shopify's 'slate' package not running after installation

I just installed Shopify's 'Slate' package using npm.
Terminal shows that the package was added to '/.npm-packages/lib'.
However, when I attempt to build a new shopify theme using the command 'slate theme newthemename', the command isn't found...
...even though slate clearly was installed.
Curious to figure out what I'm doing wrong, so any help/advice is much appreciated!
Please execute the below command from your terminal.
npm link #shopify/slate
Basically this command creates a symlink to your package folder, it will check for the global (npm) modules first, and will check for the local modules if there is no match.
Hope this helps!
Your installation of slate is successful. However, the slate program (slate/lib/index.js) is not added to environment variable PATH, that's why error command not found is reported.
To fix this issue, a simple method is add slate/lib/index.js to PATH manually. For example, create a symbolic link in /usr/local/bin/ and make it point to slate/lib/index.js:
sudo ln -s /<absolute_path>/#shopify/slate/lib/index.js /usr/local/bin/slate
Please note the first parameter of ln -s must be absolute path. If relative path is used, Mac OS X (I'm on 10.12.6) won't help to translate it.

How to change default directory for a command in Bash?

Firstly, I am new to Linux so excuse me if any terminology is wrong; I'll try to phrase the problem as competently as possible.
I have installed Ruby (2.4.0) via Linuxbrew. The ruby command works fine; it installed correctly. However, when I try to use the gem command (which Ruby should have installed) I receive this error:
bash: /usr/bin/gem: No such file or directory
Now, because I installed this with Linuxbrew I know that this directory isn't correct. For example:
result of which gem : /home/me/.linuxbrew/bin/gem
result of which ruby : /home/me/.linuxbrew/bin/ruby
Therefore, it seems gem is installed but the gem command isn't linked to the correct path. I assume I need to direct the gem command to the path of which gem as opposed to /usr/bin/gem that bash is saying doesn't exist. How would I go about changing this? I tried in vain to change the bash_profile but I'm not sure what to do.
Again, excuse me if ruby and gem are not referred to as commands and if the problem isn't the "default directory" as stated in the title. I wasn't sure how to label it.
EDIT/TL;DR:
Basically, how can I make gem execute this: /home/me/.linuxbrew/bin/gem instead of looking for the program in /usr/bin/gem?
Instead of running gem, run /home/me/.linuxbrew/bin/gem, i.e. type the full path name (followed by any arguments you may need).
If this becomes too tiresome, you could change your PATH. Prepend your bin directory with
PATH=$HOME/.linuxbrew/bin:$PATH
First, the reason you get the error /usr/bin/gem not found, is that earlier in the same shell session, the file used to be there. Bash will cache this to speed things up when running the same command many times. Running hash -r will clear this.
Editing PATH you seem to have managed, hence the which command gives the result it does.
To answer my own question-
As I had previously installed and uninstalled Ruby via apt-get instead of Linuxbrew in the same Terminal window, Bash was looking for gem in usr/bin as opposed to the path specified in my bash_profile to Linuxbrew.
Therefore, Stian's answer above with hash -r would also work, I am sure.

teach me how to set up a path correctly

I installed casperjs by npm install command on my mac os x.
But, when I try using casperjs in command line, it gives me the error below.
$ casperjs cas.js
-bash: /usr/local/bin/casperjs: No such file or directory
I checked if casperjs is installed by using which command.
The result is below.
$ which casperjs
-bash: /Users/Hayato/.nodebrew/current/bin/casperjs
I think what I need to do is to setup a path in a different way so that when I run "casperjs test.js", it runs "/Users/Hayato/.nodebrew/current/bin/casperjs" instead of "/usr/local/bin/casperjs".
But, I'm not familiar with this kind of terminal task, and don't know how to do this.
Please could anyone teach me how to setup a path correctly?
Thanks!
If you want to use casperjs in the directory you specified, add this to your ~/.bash_profile
export PATH=/Users/Hayato/.nodebrew/current/bin/:$PATH
Save the file
That will add all scripts in the /Users/Hayato/.nodebrew/current/bin directory to your path.
After that.. close the terminal and then reopen it:
You can check the path by doing:
echo $PATH
You should see the path you just added.
Then when you do the following:
which casperjs
it should use the new location.
Let me know if this works for you!
But, the issue may be something deeper, did you get errors when you installed casperjs via brew?
You may want to try linking it again using
brew link casperjs
If that doesn't work you may have some permission issues.
Check out these previously answered questions:
brew link didn't complete
Fixing homebrew permissions

Modifying $PATH variable

Trying to install node.js.
Did brew install node
It seems to have worked.
However, received this message upon its completion
Homebrew installed npm.
We recommend prepending the following path to your PATH environment
variable to have npm-installed binaries picked up:
/usr/local/share/npm/bin
Ok ... so, I open my bash_profile...
And this is what I have in it:
export PATH="/usr/local/bin:/usr/local/sbin:~/bin:$PATH"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
Trying to understand how to modify it correctly so I won't ruin it ...
Do I add /usr/local/share/npm/bin like this
export PATH="/usr/local/bin:/usr/local/sbin:~/bin/usr/local/share/npm/bin:$PATH"
If not, what is the correct way to add that path?
Thank you for any help provided!
PS. let me know if there is any additional information I could have provided
EDIT
upon seeing which npm in macedigital's answer, I ran that ...
and got this: /usr/local/bin/npm
and that was before I did the second answer (ie, ThiefMaster's answer).
ran which npm again ...
and got the same answer as before ...
i did echo $PATH and got this:
/Users/name/.rvm/gems/ruby-1.9.3-p374/bin:/Users/name/.rvm/gems/ruby-1.9.3-p374#global/bin:/Users/name/.rvm/rubies/ruby-1.9.3-p374/bin:/Users/name/.rvm/bin:/usr/local/share/npm/bin:/usr/local/bin:/usr/local/sbin:~/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin:/usr/local/git/bin
So, it looks like I already had it installed?
Therefore, how do I handle the answers? I hate leaving it unresolved since both of you were so helpful and I feel bad that I asked without providing echo $PATH information since that would have told you that I had it installed ...
EDIT 2
ls -la /usr/local/share/npm/bin gets this:
ls: /usr/local/share/npm/bin: No such file or directory
which -a npm gets this: /usr/local/bin/npm
EDIT 3
ls -a /usr/local/bin/npm gets this: /usr/local/bin/npm
there's no timestamp...
Short answer, do this (notice the additional colon I inserted):
export PATH="/usr/local/share/npm/bin:/usr/local/bin:/usr/local/sbin:~/bin:$PATH"
The $PATH environment variable is colon separated list of directories to look in if you want to run a command without a fully qualified path (e.g. running npm instead of having to type /usr/local/share/npm/bin/npm).
You can try this from a terminal before actually saving the change in bash_profile. If everything is good, which -a npm will show you all fully qualified path(s).
UPDATE
It is not necessary to modify the $PATH variable in order to use npm. What homebrew install recommends instead is to add the directory where npm-installed binaries are stored to the $PATH variables, so its more convenient to use them from the command line later on.
Node modules like phantomjs, phonegap, express, etc. provide binaries which after the change are available on the command prompt without having to type the full path.
The cleanest solution is adding the following between the two lines you posted:
export PATH="/usr/local/share/npm/bin:$PATH"
That way everything stays readable and you prepend it to PATH just like the program suggested it. And if you ever want to undo the change you just remove that line instead of editing a possibly long line.
In PATH ORDER IS IMPORTANT. So anything before desired npm version will still cause problems.
#adding in first place of the path, before anything else
export PATH=/usr/local/bin:otherPathEntries:$PATH
assuming that version of npm You want is in /usr/local/bin, to check all use 'which -a npm'

Node.js Cygwin not supported

I am trying to install node.js. I followed this tutorial and i am stuck in the middle.
When I write ./configure in my cygwin terminal it says "cygwin not supported". Please help me out
Thanks in advance.
Node in my experience runs fine in cygwin, what Node usually has EINVAL errors in seems to be MINTTY which is a terminal emulation 'skin' that is default to cygwin. I still am not sure why these EINVAL errors happen 100% but the following are the steps and tricks I use to get node working.
In my /cygwin/home/{username}/.bashrc I add node to path so cygwin can find it
export PATH=$PATH:"/cygdrive/c/Program Files/nodejs/"
If you run a 32 bit version of node:
export PATH=$PATH:"/cygdrive/c/Program Files (x86)/nodejs/"
Then to make npm run without windows to linux issues I launch cygwin in admin mode then run:
dos2unix '/cygdrive/c/Program Files/nodejs/npm'
At this point running files and most npm packages will run in MINTTY just fine, although every once and awhile you will run into EINVAL issues with certain npm packages as karma. Also you will not be able to run the interpreter directly in MINTTY, anytime I want to do these things I run:
cygstart /bin/bash
This will open a native cygwin bash.exe window, from here you run the interpreter or an any troubling package command that results in a EINVAL. It slightly sucks you have to do this but I rarely use this day to day, and I love MINTTY too much to not use it.
Also note that you can run any one line node code in MINTTY by just running something like:
node -e "console.log('hello node')"
As a simpler derivative of troy's answer for those just looking to install NPM packages:
Install Node.js with the Windows installer package.
Add it to the PATH with export PATH=$PATH:"/cygdrive/c/Program Files/nodejs/" (obviously replacing the path to Node.js's installation directory with where you installed it).
There's a current bug in the Windows version that can be fixed by running mkdir -p ~/AppData/Roaming/npm. This is a bug for all of Windows and not just Cygwin. At some point of the future, you won't have to do this anymore, but the command shouldn't have any negative side effects.
Test it. Eg, npm install pretty-diff -g.
In order to be able to run the newly installed software, you'll need to add the install locations to your PATH. You can find these with npm bin -g and npm bin (the -g flag is the "global" installation location).
Not really anything special that you have to do to get it to run in Cygwin (although I can't say if everything works).
Use Console2, it allows you to run create tabs of CLI shells. It seems running cygwin inside console2 allows me to use node REPL just fine. I have no idea why :P
Follow this guide to add cygwin to console2:
http://blog.msbbc.co.uk/2009/11/configuring-console-2-and-bash-with.html
With Bjørn's suggestion (using Console2) and Soyuka's alias (steps here), my node.js v0.10.13 and npm v1.3.2 are now working under Babun v1.02, a Cygwin distribution.
For windows, Just run bash.exe in cmd, so that you could have a bash work around with cmd console directly, which could support ALL NODE WORKING PERFECTLY.
C:\Users\郷>bash
郷#CHIGIX ~
$ node
>
I'm using this wrapper in /usr/local/bin/node (note no extension!)
#!/bin/sh
_cmd="$(cygpath -lw -- "$1" )"
shift
"/proc/cygdrive/C/Program Files/nodejs/node.exe" "$_cmd" "$#"
This is far from perfect, as Node do not understand Cygwin directory tree, but works relatively well with relative names.
From Windows, run Cygwin.bat (instead of Cygwin Terminal) then in that run node: see and reply on this answer on this effectively-same question asked 1.5 years later.
Grab and run the node.js Windows installer.
In the Cygwin prompt type node
See if it works.

Resources