The following is my .profile file:

# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
    . "$HOME/.bashrc"

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    export PATH=/home/naveen/bin:~/../../usr/local/MATLAB/R2015a/bin/:$PATH

The path to matlab (~/../../usr/local/MATLAB/R2015a/bin/) was recently added. But, after adding the matlab path, I am still NOT able to run matlab from ANY folder by simply running the command ./matlab.

I am adding the path correctly ?

Should I reboot the system for the changes to apply ?

  • 1
    It seems that you have three problems here: 1) Do not use ~ to refer to your $HOME; 2) Do not forget to do source ~/.profile to activate the script (it won't be necessary afterward) 3) Do not call ./matlab but matlab. – perror Aug 26 '15 at 19:31

A reboot isn't necessary, but reloading your .profile is. Try running source .profile. Alternatively, you can log off and log on again.

| improve this answer | |
  • Ah, I forgot this also... Combine the two answers... – perror Aug 26 '15 at 19:27
  • The changed suggested by @Gilles followed by reloading did the trick. Thanks! – Naveen Aug 26 '15 at 19:33

The main problem is that ./matlab runs the executable called matlab in the current directory. To look for it in $PATH, you need to type just matlab. The PATH variable is only used when there's no slash in the command name.

Also, remove the export PATH=… line and instead add




before the if [ -d "$HOME/bin" ] line. There's already code to add /home/naveen/bin (assuming that's your home directory, and if not $HOME/bin is the correct one to add), so you don't need to add it again. If $HOME/bin doesn't exist, you still want to add the Matlab directory, so it belongs outside the if. Use an absolute path, a relative path makes no sense here. Add the Matlab directory either first or last depending on whether you want Matlab executables to have priority over other executables by the same name in different directories (there are probably no executables by the same name, in which case it doesn't matter).

You don't need to reboot. However, .profile is only read when you log in. You can also reload it for a terminal session by typing . ~/.profile in the shell; this only applies to programs started from that particular shell.

| improve this answer | |

Your example wouldn't do anything if $HOME/bin doesn't exist. Maybe try this instead:

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then

And, running ./matlab will never work (if matlab is not in the current directory) because you are trying to run matlab specifically in the current directory. Simply run matlab.

Another option would be to symlink matlab into your $HOME/bin instead of adding it to the path (if it is the only executable you want to run from there:)

ln -s /usr/local/MATLAB/R2015a/bin/matlab ~/bin/

Edit: And you'll need to logout or run source ~/.profile in every shell.

| improve this answer | |

Try to type simply matlab and not ./matlab.

The ./ means that you are looking for the executable matlab in the current directory without going through the PATH variable.

| improve this answer | |
  • Yes. Tried that. I get a 'matlab: command not found' error. – Naveen Aug 26 '15 at 19:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.