Mac OS terminal doesn't find commands - macos

I have weird problem as all of the sudden terminal stopped reading any commands. Last weekend I installed Wordpress with PHP and mySQL and since that moment didn't have time to do anything more on laptop. Now I wanted to launch some react-native code but command wasn't found, then I tried different things to use some other commands and each time I get message
MBP-Mateusz-2:business-cards-native mateusz$ code .
-bash: code: command not found
and doesn't matter what command is that except standard ones like ls, cd etc. However when I try to write npm --version, or node --version, or launch visual studio code like before with code ., each time I get command not found. Doesn't anyone have issue like that? How to fix it as I'm super confused and have no idea even where to start.

You probably messed up your PATH environment variable, and now your computer cannot find the commands if you don't tell it directly where. The PATH variable contains the directories where the system should look for binaries if they're not in the current directory. If it gets corrupted for some reason, you won't be able to run any program from the terminal unless you pointed directly its location.
I would first run this command:
echo $PATH
so you can see which is the content of the PATH.
If it seems empty, or some critical folders are missing, try to add them temporarily:
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
Then try to run the commands again from the same terminal and see if that worked.
If that works, check if you have a ~/Library/LaunchAgents/environment.plist file and its content. It is possible that there is a key for the PATH and that its values are pointing something of your Wordpress stack but not the system directories.
If that looks fine, look at the ~/.bash_profile file. Find any export PATH instruction that may explain your issues. If you can't find any, but still exporting the PATH worked out, add at the end of the file that instruction as a workaround for fixing the mess:
export PATH=$PATH:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
(notice that I'm ading $PATH in this last case so if there is any other path actually configured it is added as well)
Good luck.
EDIT: That's the usual issue people has, but now that I've read your comments, the issue seems a bit more serious. It looks like the mySQL setup destroyed your /usr/local/ folder, which means you lost all the binaries located there npm, code, etc.
If you have a backup of the whole filesystem (which by experience is unlikely), restore /usr/local folder.
If you don't have any backups, you can reconstruct /usr/local... by reinstalling the software that cannot be found. Reinstall npm, VSCode, etc, that will place their executables again in the /usr/local folders and from there you'll be good to go. Install brew (since it's likely that also got deleted) then try brew install node and see if now you can run npm. If that works out, I'm afraid you'll have to reinstall all the software you lost again.

Related

Why /user/local/go isn't recognized as a Go SDK in GoLand

I'm trying to setup GoLand to use WSL 2 as in this guide: https://www.jetbrains.com/help/go/how-to-use-wsl-development-environment-in-product.html
I've installed Go in the Ubuntu distro following the linux instructions on the GoLang website, and go version prints outs the version I downloaded, so it appears that Go is working inside WSL.
So now I tried to create a new project in GoLand, and I'm getting errors, which appear to come from the fact that the SDK isn't loaded in GoLand. The guide doesn't offer much guidance on this, so I just tried to add a local SDK.
When I select /usr/local/go I get an error that it's not a valid SDK.
So I created the ~/go directory, and then updated my .zshrc file to export the GOPATH and GOROOT environment variables, even though they already showed up when I ran go env, doing this got them to show up on a simple env call.
But I'm still getting the invalid SDK error like above.
Is there a configuration step I'm missing that isn't spelled out in the guide? I came across this old post about creating symlinks to fake the expected directory structure. I haven't done this because it's a really old post, has comments that say this has been fixed, and seems like a really odd solution.
Support for Go SDK in WSL2 will be available in the next 2021.3 release, please see GO-10618.
October 2021 update.
2021.3 reaches Early Access Program at the moment. GoLand suggests selecting Go SDK on WSL2 mount if the location of the project is on WSL2 as well.
I experienced this on my Debian machine and I wasn't using WSL2. I found that the actual cause of the issue is that Goland is unable to read the directory /usr/local/go/bin due to inadequate permission.
A possible solution is to run the goland.sh script as root. The script can be found in the bin/goland.sh directory of the Goland IDE folder. Here is a simple command to do run Goland as the root
export HISTIGNORE='*sudo -S*' && echo "sudo-password-here" | sudo -S /absolute-path-to-goland.sh
export HISTIGNORE='*sudo -S*' tells bash history to ignore caching any command matching sudo -S* to bash history. This way, your sudo-password isn't saved into the bash-history file.
echo "sudo-password-here" | pipes your sudo password as input to the next command.
sudo -S tells bash to read input for password prompt from stdin, which has been provided through the echo command.
Alternatively, you can just install the latest version of Goland. Hopefully, it doesn't come with this bug

-Bash Shell Script "No such file or directory"

Pretty new to coding and I am running into an error I've never seen before and would really appreciate any help navigating this :( Thank you!
I wanted to delete nvm, so I removed the folder following the advice given on StackOverflow. That FINALLY successfully deleted node from my mac (wanted to uninstall because I was running into dependency errors). The I used brew install to reinstall node. I can find the path to the node file (using which node). However when I run node -v I get the following bash (shell script??) error: -bash: /Users/Cindy/.nvm/versions/node/v12.14.1/bin/node: No such file or directory
I also followed #1219 and went into my bash_profile to delete the lines related to nvm. Now I don't know how to move forward with this.
I just want to be able to download node and run it properly to prepare for an interview in React and JS but I ran into these nasty bugs instead and morale is low. I'm lost now and I'm not sure if I just completely ruined my computer.

how can i delete git from $PATH or change path so that it no longer contains it (macOS)

I have recently updated git and it has changed my path to
/usr/local/git/bin:/usr/local/bin:/usr/local/sbin:/matthew/git
I try to use composer and execute files and I get the error
env: php: No such file or directory.
when
I reset the path back to
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
everything works fine and composer loads but the only thing is it automatically sets the path back to /usr/local/git/bin:/usr/local/bin:/usr/local/sbin:/matthew/git in a matter of seconds after me doing what I need to do.
i thought the path would stay and go back to the original one i reset it to but it auto reverts back to the git one
Is there any way i can fix this without having to reinstall the operating system? and keep the path as PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" i have been stuck on this for two days i just want rid of git
you should update your .bash_profile file
you can check this guide for futher details
#funkyjelly thanks but this was still no good ended up having to reinstall the operating system and install git via home brew and the problem with the path was solved

Stardog Command not found

I am trying to get to install stardog on mac 10.8.5 using the instructions provided at http://docs.stardog.com/quick-start/.
The export path particular directory has been created and for which echo’ed to make sure that environmental variable is set up. The license key that is provided is also in the correct directory. When I try to run “$ ./stardog-admin server start” the command is not recognized. So I tried to create an export PATH to stardog’s bin, which did not work either.
I have also tried manually adding the path in the following:
- ~/.bash_profile
- ~/.profile
Still no luck, any ideas?
Using zsh I had a similar problem. For some reason, the docs suggest that from the stardog-directory-name directory you can run the command, but it didn't work until you cd into the bin directory. Once there ./stardog-admin server start should run correctly.
It sounds like you simply have something incorrect in your .bash_profile or .profile. If you run either of the stardog scripts from it's bin directory, it will work. If you're getting a command not recognized error, that sounds like bash cannot find the stardog-admin script.

Sudo Won't Work after change/mistake in Path env

I'm a Mac newbie and just upgraded to Node.js 0.67. After running node, the installer says "Make sure that /usr/local/bin is in your $PATH."
And I try to run node but as expected, it doesn't run without the path change.
So not really knowing what I'm doing (yes!), after some research I do this:
export "PATH=/usr/local/bin"
And node runs. But sudo doesn't. Which I think means I screwed up the environment variables.
sudo: command not found
Then in another Terminal window (that was open when I messed this up), sudo does respond; both windows have the same path. But in that window, npm is no longer available.
Can anyone help get me back to sudo stability?
sudo on a Macintosh lives in /usr/bin.
Make sure /usr/bin is in your $PATH environment and you should be okay.
And to do that, in the context of your question above, do something like:
export "PATH=$PATH:/usr/local/bin"
The idea here being that you are appending a new search path to the already existing list in your PATH environment variable.
Here is a potentially useful tutorial you can refer to.

Resources