How do I fix the "Specified path is too long" error?

How do I fix the following error in mac "sudo: export: command not found" when I enter "sudo export PATH=/Users/SystemName/Downloads/mongodb/bin/mongod: $PATH"?

  • This is how my bash_profile looks export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:$PATH When I do echo $ PATH I get this MacBook-Pro:~ Sqube$ echo $PATH /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/mysql/bin This is what I see when I do MacBook-Pro:~$ vi ~/. ./                   .bash_history        .m2/ ../                  .bash_profile        .mongorc.js .CFUserTextEncoding  .dbshell             .vim/ .DS_Store            .gitconfig           .viminfo .Trash/              .gitignore I also tried Disk Utility verify disk and repair disk. It doesn't resolve my problem. My other problem is whatever export I do, it goes off when I close iTerm and open it back. Please help me. Thanks. Also why do I see "export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:$PATH" in bash_profile I see something different in echo $PATH /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/mysql/bin

  • Answer:

    First, "export" is a "shell built-in", not a "command". "sudo" runs commands. That's why it can't find a command when you try to "sudo export". Using "sudo" before a command gives it absolute power over your machine, including the power to completely destroy everything on your hard drive or worse. It's a bad idea to use "sudo" unless you're absolutely sure you know what you're doing or you completely trust the source that told you to type it in. With great power comes great responsibility, so "sudo" is a very powerful and dangerous command and is not to be used lightly. Back to bash: Yes, "export" only takes effect for the shell session in which it's run, so the computer needs to run that "export" every time you open a new shell session. That's where the .bash_profile comes in. "bash" is a "shell". The ".bash_profile" file is a list of tasks that every new bash shell session should perform when you open it. "PATH" is a shell environment variable that tells your shell session where to find commands. "PATH" should contain directories, not commands. A daemon is a command. If the Mongo developers follow existing conventions, "mongod" is very likely short for "mongo daemon". Basically, what you probably want to do is to change the PATH line in your .bash_profile to say this: export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/SystemName/Downloads/mongodb/bin:$PATH There should be no spaces at all after the = sign in that line. (If your SystemName has space in it, then this won't work. I've never had any reason to find out if the Mac allows spaces in its SystemName.) The change should let you run "mongod" without typing the full path every time. After you make the change, make sure to open a new shell session to test it. (Open a new iTerm, for example.) Changing your .bash_profile will only take effect in new bash shell sessions. It won't affect any sessions that are already open. A few other things... "vi" is a text editor. Trying to "vi" your home directory is like trying to use a pen to move through folders in your filing cabinet. A better command for looking at your directory would be "ls". From everything you described, your disk is fine. Verifying and repairing your disk is like taking X-rays of your machine when there's absolutely no indication that there's anything wrong. While taking X-rays every now and then is perfectly safe, people are concerned about the safety of taking too many X-rays too often.

Betty Lee at Quora Visit the source

Was this solution helpful to you?

Other answers

Because export is a shell command and not a binary, and sudo only works on binaries. Let me expand on that: the shell has a certain number of things built into it because they're actual functions of the shell itself. The 'export' command is one of those: it sets an environment variable in the shell to the value you specify. It doesn't actually go out and find a program called something like /usr/bin/export, but runs code right inside the shell itself to do the job. Sudo, on the other hand, looks for a binary (also known as an executable, short for "executable file') that it can run like this: The shell spawns off a subprocess to run sudo (#1) with the given parameters. This is still with your privileges. This process runs sudo, which authenticates you and confirms your right to execute the specified command. The process running sudo now spawns off another subprocess (#2) to execute the specified command with the altered privileges. The sudo process waits for the subprocess it spawned off (#2) to exit. After process #2 exits, the sudo command exits, returning control to the subprocess spawned by the shell (#1). Subprocess #1 spawned by the shell exits, returning the user to the shell prompt. (I'm drawing on one of the excellent answers on Ask Ubuntu for http://askubuntu.com/questions/291666/why-doesnt-sudo-cd-var-named-work for the details on how sudo does its job.) What you need to do is just set the environment variable normally, no sudo, then run the command you want with sudo -E /usr/bin/whatever, where "/usr/bin/whatever" is the real command. The -E flag says "preserve the environment and pass it to sudo".

Joe McMahon

Don't use sudo for export path. It doesn't require sudo.

Pankaj Saraf

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.