From the docs I tried doing:
npm i -g netlify-cli
Success! Netlify CLI has been installed!
Your device is now configured to use Netlify CLI to deploy and manage your Netlify sites.
Next steps:
netlify init Connect or create a Netlify site from current directory
netlify deploy Deploy the latest changes to your Netlify site
For more information on the CLI run netlify help
Or visit the docs at https://cli.netlify.com
+ [email protected]
updated 1 package in 129.372s
$ netlify init
-bash: netlify: command not found
Environment versions:
$ node -v
v11.7.0
$ npm -v
6.10.2
I've tried restarting my macbook. I couldn't find a similar issue which means this might be very uncommon. Can someone tell me how can I add netlify to my PATH, so that it will work?
Hi have experienced the same, but if you install netlify-cli as a devDependency, you can then use yarn or npx to run netlify.
Thank you very much, I am now able to do it for now. But what causes this problem?
@zemse Thanks for reporting this problem. Are you able to access the other globally installed packages on your computer? Please try installing something like npm i -g eslint and report if you can run eslint from any directory
Just installed eslint globally and tried it with eslint:
% eslint
eslint [options] file.js [file.js] [dir]
Basic configuration:
--no-eslintrc Disable use of configuration from .eslintrc.*
-c, --config path::String Use this configuration, overriding .eslintrc.*
config options if present
...
Seems other packages are working, I never had such problem. Again tried doing:
% npm i netlify-cli -g
npm WARN deprecated [email protected]: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
npm WARN deprecated [email protected]: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)
/Users/sohamzemse/.npm-global/bin/ntl -> /Users/sohamzemse/.npm-global/lib/node_modules/netlify-cli/bin/run
/Users/sohamzemse/.npm-global/bin/netlify -> /Users/sohamzemse/.npm-global/lib/node_modules/netlify-cli/bin/run
> [email protected] postinstall /Users/sohamzemse/.npm-global/lib/node_modules/netlify-cli
> node ./scripts/postinstall.js
Success! Netlify CLI has been installed!
Your device is now configured to use Netlify CLI to deploy and manage your Netlify sites.
Next steps:
netlify init Connect or create a Netlify site from current directory
netlify deploy Deploy the latest changes to your Netlify site
For more information on the CLI run netlify help
Or visit the docs at https://cli.netlify.com
+ [email protected]
added 106 packages from 107 contributors, removed 47 packages, updated 81 packages and moved 15 packages in 154.974s
% netlify init
zsh: command not found: netlify
Hi @aimee-gm @RaeesBhatti, I've figured this issue. This has nothing to do with netlify, it's an issue of $PATH variable. MacOS moved from bash to zsh and your existing npm installation is configured to add binaries to bash. You have to manually add it to zsh.
Steps to fix:
See where npm i -g installs the global dependencies.
% npm config get prefix
/Users/<yourusername>/.npm-global
Your binaries would be in /Users/<yourusername>/.npm-global/bin.
If you add the binaries directory to the path variable, by running export PATH=/Users/<yourusername>/.npm-global/bin:$PATH, you can immediately run the binaries, in this case netlify.
But if you close terminal then the binaries won't be present in the path variable hence the command not work again.
To permanently add it to path, edit ~/.zshrc, if it doesn't exist the create one and paste the export in it.
export PATH=/Users/<yourusername>/.npm-global/bin:$PATH
Restart the terminal. Done.
Hi have experienced the same, but if you install
netlify-clias a devDependency, you can then useyarnornpxto runnetlify.
How do I use "yarn" with "netlify"? because "yarn deploy --prod" is not working :(
@alfredrafael add a netlify-cli script to your scripts in package.json and install netlify-cli as a dev dependency.
"scripts": {
"custom-script-name": "netlify init",
}
Then you can yarn custom-script-name or npm run custom-script-name. Does this solve your problem? Also looks like you already have a script deploy which is giving you error, what's the script in it and error?
Any knowledge of how to fix this in Windows in bash?
Most helpful comment
Hi @aimee-gm @RaeesBhatti, I've figured this issue. This has nothing to do with netlify, it's an issue of
$PATHvariable. MacOS moved from bash to zsh and your existing npm installation is configured to add binaries to bash. You have to manually add it to zsh.Steps to fix:
See where
npm i -ginstalls the global dependencies.Your binaries would be in
/Users/<yourusername>/.npm-global/bin.If you add the binaries directory to the path variable, by running
export PATH=/Users/<yourusername>/.npm-global/bin:$PATH, you can immediately run the binaries, in this casenetlify.But if you close terminal then the binaries won't be present in the path variable hence the command not work again.
To permanently add it to path, edit
~/.zshrc, if it doesn't exist the create one and paste the export in it.Restart the terminal. Done.