# teaching your shell how to find M2

Perhaps you have typed M2 into a shell window and gotten something like the following response:
     % M2
bash: M2: command not found
If so, then you have to teach your shell how to find M2.

Your shell will look for M2 in the directories listed in the value of the PATH environment variable. You will want to arrange for that value to get set when you log in or when you start your shell. The former is preferable, because environment variables are inherited by new processes only from their parents, and your login shell is an ancestor of all of your processes.

If you teach your shell how to find M2, then emacs may be able to find M2, also.

The simplest way to teach your shell how to find M2 is to let M2 do it for you. Assume that you have found M2, and it is located at the path /foo/bar/bin/M2. Run the command /foo/bar/bin/M2, and then, in response to Macaulay2's input prompt, enter setup(). If that works, the next time you log in or start a new shell, the shell should know how to find M2 (see setup). If that doesn't work, read onward.

Your goal is to add the directory containing M2 to the value of the PATH environment variable. For this, you must know where the Macaulay2 files are: see finding the Macaulay2 files. Your system administrator may have installed the Macaulay2 files under /usr, in which case you will see M2 in /usr/bin, and you can ignore the rest of this section. The files may also be installed under /usr/local, in which case you will see M2 in /usr/local/bin, and you can ignore the rest of this section, provided you have /usr/local/bin on your PATH. Or the files may be installed somewhere else, such as in /Applications/Macaulay2, in which case you will see M2 in /Applications/Macaulay2/bin, and you will want to add that directory to your path now.

The method for setting environment variables depends on which shell you are using. Typical shells in use include ash, bash, csh, tcsh, ksh, sh, and zsh. The command languages understood by these shells differ, but they fall into two main classes: the Bourne shells sh, bash, ash, zsh, and ksh; and the C shells csh and tcsh.

## Bourne shells

A Bourne shell reads commands from the file .profile in your home directory when you log in, except perhaps under Mac OS X. The bash shell will also read commands from .bashrc each subsequent time it starts up, after the initial log in. To add a directory called, say /foo/bar/bin, to your PATH, put this command in your file .profile:
     export PATH=/foo/bar/bin:$PATH It will be acted upon the next time you log in, or the following shell command will run those commands in your current shell.  source$HOME/.profile

## C shells

A C shell reads commands from the file .login in your home directory when you log in, except perhaps under Mac OS X. The shell will also read commands from .cshrc or perhaps .tcshrc. Check the man page of your shell.

     setenv PATH /foo/bar/bin:$PATH It will be acted upon the next time you log in, or the following shell command will run those commands in your current shell.  source$HOME/.profile

## making a link to M2

Another way to proceed that sometimes works is this. Look at the output from the shell command:
	  printenv PATH
and see whether one of your own directories is already on the path. If so, say it's ~/bin, then you can make a symbolic link from M2 to that directory, and it will appear on your path. First ensure the directory has been made with this command:
      mkdir ~/bin
Ignore the error message if the directory already exists. Then make the symbolic link with this command:
	  ln -s /Applications/Macaulay2/bin/M2 ~/bin/M2
After that your shell will be able to find M2, and M2 will be able to find its files (because it knows about symbolic links). (Don't use a hard link.)

## what else to try

If you fail to teach your shell how to find M2, then all is not lost. We prefer to run M2 within emacs, and it is enough to teach emacs how find M2. See teaching emacs how to find M2.