I installed yarn globally, but got error "zsh:command not found : yarn" - npm

npm install -g yarn
> yarn#1.22.15 preinstall /Users/myname/.npm-global/lib/node_modules/yarn
> :; (node ./preinstall.js > /dev/null 2>&1 || true)
/Users/myname/.npm-global/bin/yarn -> /Users/myname/.npm-global/lib/node_modules/yarn/bin/yarn.js
/Users/myname/.npm-global/bin/yarnpkg -> /Users/myname/.npm-global/lib/node_modules/yarn/bin/yarn.js
+ yarn#1.22.15
As I use a mac, I opened the zshrc file.
and then write the code below
export PATH=$PATH:/Users/myname/.npm-global/lib/node_modules/yarn
However, when I entered the yarn --v command, I got the same error as the title.
Could you please tell me what the problem is? What should I do when I have installed a variable globally?

Add the global npm bin to PATH instead:
export PATH="$PATH:$(npm bin -g)"
In your case, this is the same as:
export PATH="$PATH:/Users/myname/.npm-global/bin"

Here is what worked for me on the Mac OS Monterey 12.3.1
npm install -g yarn
npm config get prefix
My command output was: /Users/my_username/.npm-packages
Append that in your /etc/paths using nano
Open up Terminal.
Run the following command:
sudo nano /etc/paths
Enter your password, when prompted.
Go to the bottom of the file, and enter the path you wish to add.
Hit control-x to quit.
Enter “Y” to save the modified buffer.
That’s it! To test it, in new terminal window, type:
echo $PATH
You will see /Users/my_username/.npm-packages/bin appended to your path
Yarn should now work
yarn --version
You will see 2.4.x

Related

install packages globally in google cloud platform

I'm trying to install some npm packages globally in google cloud platform each time the shell started.
I added these commands in $HOME/.customize_environment file.
#!/bin/sh
date -u
npm i -g #angular/cli
then, I open the file /var/log/customize_environment to see the log output from $HOME/.customize_environment
I found it executed and the date is displayed (the first line)
but npm couldn't installed with this error npm command not found
npm commands are available after the cloud shell starts, so I guess the file $HOME/.customize_environment is executed before installing node.
I tried to use the full path: /usr/local/nvm/versions/node/v12.14.1/bin/npm i -g #angular/cli, but I got this error
/usr/bin/env: ‘node’: No such file or directory
is there a way to automatically install npm packages globally?
The path env var isn't set or active. Use the full path of NPM location like that
/usr/local/nvm/versions/node/v12.14.1/bin/npm i -g #angular/cli
Be careful. if Cloud Shell update the version of NPM the path will change.
You can also try to add your NPM (without full path) command at the end of the ~/.bashrc file.

Expo-cli installed but when running any expo command I get "zsh: command not found: expo"

I have installed expo-cli globally but when I try to run any expo code like expo start from anywhere, I get:
zsh: command not found: expo
echo $PATH returns:
/Users/amitg/.rbenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/amitg/.npm-global/bin
I am using macOS, catalina.
The correct command to run expo in macOS these days is npx expo.
e.g.
npx expo init my_app
If expo-cli is not installed, it will provide you with instructions to install
The answer is pretty simple.
just add npm binaries to your path
echo $PATH
export PATH=$PATH:~/.npm-global/bin
source ~/.profile or source ~/.bash_profile
That's It, It will work now, Just go check it
expo init myproject
FOR MACOS
So I recommend your echo $PATH command should be /usr/local/bin. Probably you have install Node on the website via .pkg you have downloaded. I have tried to remove and reinstall multiple times but it wasn't work on MacOS Catalina. I highly recommend to install via NVM. Okay I got you at first it sounds like you don't want any third party dependency to install more than Official website of NodeJS, alright I understand your concern, but I have tried for 2 hours straight and it is not worked. NVM is not really that bad, it is helpful and handy and you don't have to reinvent the wheel. I will show you very simple way, no mess up.
So I recommend you to remove and uninstall it first:
brew uninstall node
which node //if this not found or return empty it means you have removed it
sudo rm -rf /usr/local/bin/node
sudo rm -rf /usr/local/lib/node_modules/npm/
brew doctor
brew cleanup --prune-prefix
Then:
brew uninstall --ignore-dependencies node
brew uninstall --force node
MAKE SURE YOU ARE DEACTIVATE ANY VIRTUAL ENVIRONMENT ***:
brew update
brew install nvm
Then create folder for NVM (no need to care which directory you are in now)
mkdir ~/.nvm
Now add these lines to ~/.bash_profile ( or ~/.zshrc for macOS Catalina or later) by nano ~/.bash_profile: (Marks my word, ADD belows line to bash_profile or zsh, not running those two commands below, ADD THEM!!!)
export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh
Add the NVM Directory Paths to Your Shell Profile (When Needed)
nano .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
Type CTRL + x in your Mac
Type Shift + y in your Mac
Hit Enter or Return key
Then you need to QUIT/CLOSE ALL TERMINAL entirely to make effect
To see what Node versions are available to install run:
nvm ls-remote
You will see list of Node version available. I recommend to install any node version with Latest LTS (green color text)
For me, I just needed the latest point release of Node version 12.8.4 LTS stable released during my answer for you so I ran
nvm install 12.18.4 or nvm install --lts
Otherwise a useful reference in 2022: https://heynode.com/tutorial/install-nodejs-locally-nvm/
Verify your node version:
node --version
THEN FINALLY INSTALL expo cli
npm install --global expo-cli
Check expo installation:
expo --version
I am a student I tried many ways and this work for me and I hope I would be part to help you. Comment if sth still go unplanned.
I am getting the same loop. This is how you fix your expo-cli.
npx uninstall -g expo-cli
npx update (in your project directory).
Works like a charm. No endless loop. No editing the bash or zsh files.
I had the same problem when switched from bash to zsh, I solved it by checking at my .bash_profile (wich is located at ~/.bash_profile) and I found this export:
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
given that in bash everything worked correctly I decided to copy the export and replace default export in .zshrc file (wich is located at ~./zshrc)
Your ~/.zshrc file should look something like this:
# If you come from bash you might have to change your $PATH.
#export PATH=/usr/local/bin/npm:$PATH
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"
Then restart your terminal by pressing cmd + Q and you're done, hope this helps.
If none of the above work for you try:
sudo npm install --unsafe-perm -g expo-cli
hopefully this helps.
use "sudo yarn global add expo-cli" instead of "yarn global add expo-cli"
When i got a new macbook i faced the same challange.
Here's how i fixed the issue:
alias expo="npm config get prefix/bin/expo"
Now try expo start again, it should work.

react-native: command not found in ubuntu 18.04

I am trying running react-native from last 2 days but I am not able to run anything ,I followed official page for getting started and followed instructions carefully but everytime terminal gives me this error
npm -v 6.9.0
node -v v12.6.0
java -version
openjdk version "1.8.0_212"
these are the versions of requirements i have installed
I copy pasted
export ANDROID_HOME=$HOME/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
these inside of .bashrc file in home
can anyone save me please
React Native site has good installation guide for React Native CLI on Linux, but sometimes command npm install -g react-native-cli fails with error
checkPermissions Missing write access to /usr/lib/node_modules
because only root can access directory where NPM install global packages. You might want to run sudo npm install -g react-native-cli but you shouldn`t.
(If you did it, run please:
sudo chown -R $(whoami) ~/.npm
to eliminate consequences).
The most preferred solution will be changing npm’s default directory:
create a directory for global installations:
mkdir ~/.npm-global
Configure npm to use the new directory path:
npm config set prefix '~/.npm-global'
Open ~/.bashrc (or ~/.profile) file and add this line:
export PATH=~/.npm-global/bin:$PATH
On the command line, update your system variables:
source ~/.bashrc
Now you can install react-native-cli globally without using sudo:
npm install -g react-native-cli.
After that react-native init should work.

Expo command is not found ubuntu

I have installed expo with this command - npm install expo-cli -g
but when I am writing expo in command line, is writing that expo in not found.
I have tried to install with yarn and it was installed successful but is writing that expo in not found.
I have tried to export PATH to ~/.profile but this did not help me.
What do I need to do to make my expo project?
If it is installed, expo might not be in your PATH.
Check if npm global is in your path. $ echo $PATH,
if not in your path add npm global to your path.
get the path of your global npm npm config get prefix
add the output of the above command to your .bashrc or .zshrc file.
# replace npm-global-path with the output of npm config get prefix
export PATH=npm-global-path/bin:$PATH
then
# source your .bashrc, .zshr or *.profile
source ~/.bashrc or source ~/.zshrc
Environment variables in bash_profile or bashrc?
Try npx expo init AwesomeProject, this worked for me.
Problem Solved with following steps
first of all install expo-cli using the below command line
npm install expo-cli -g
2 after installation of expo-cli set global variable using below command line
export PATH=~/.npm-global/bin:$PATH
Happy Coding!

Truffle command not found after installation

I installed truffle through npm with the following:
sudo npm install -g truffle
but when I run truffle list on the console it just gives me
bash: truffle: command not found
I had a similar problem. I ran npm i -g truffle and then when I tried to run truffle init I got an error: zsh: command not found: truffle. What solved it for me is to create a local node_modules with truffle installed in it, and then run that copy.
run npm init and make a new npm project
run npm i truffle
run ./node_modules/.bin/truffle init and it should work!
Please make sure you have the latest version of npm and node installed. I had the same issue, I updated npm and node to latest version and it worked.
npm install -g truffle works.
After installing truffle:
npm install -g truffle
Run on your project folder:
npx truffle init
I did it on a Virtual box and had the same issue, but it worked after I restarted the computer. Hopefully that works for you too
You should add the following to your path system variable.
C:\Users\UserName\AppData\Roaming\npm
(This folder contains the truffle.cmd file)
I have tried and it works.
I tried everything. Followed the instruction on official truffle website and above answers.
Still it didn't seem to worked.
Finally, this worked for me.
Go to C:\Users\Username\AppData\Roaming\npm
There you will find truffle.cmd Double click on it and your done.
npm i truffle does the exact same thing as npm install -g truffle except that installs it globally, and without -g it will be installed on the local folder. Try to update the npm, node, and probably you have a broken node installation from previous versions.
Using npm install -g truffle worked for me instead of npm i truffle
Nothing above worked for me, but I did:
nix truffle unbox react
truffle develop
atom . //opens up the react file project in the atom platform
Try to start with your command like
npx truffle <your command>
You should add C:\Users\UserName\AppData\Roaming\npm (it contains truffle.cmd file) to the path user variables. I have tried and it works
If you have a custom path for your packages, then make sure that you are exporting it when the terminal loads.
For bash:
nano ~/.profile
For zsh:
nano ~./zshrc
And add your custom path, most of the time this will be "npm-global".
export PATH=~/.npm-global/bin:$PATH
These are two simple steps the properly solve this problem for Linux Users:
1- Configure npm to install software globally in your home directory as follows :
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
2- If you are using bash, then execute the following:
echo -n "export PATH=~/.npm-global/bin:$PATH" >> ~/.profile
However, if you are using zsh instead, then execute the following command:
echo -n "export PATH=~/.npm-global/bin:$PATH" >> ~/.zshrc
Note that, if you are using both bash and zsh, it is better to execute the two commands above.