Search code examples
ruby-on-railsrubylinuxlinux-mint

Automatically Run Command Upon Opening Terminal (Linux Mint 16)


I am using Rails and for some reason unbeknownst to me I have to execute the following line every time I start the terminal in order to use ruby and rails.

source ~/.bash_profile

If I type the following before running the above command, it will recommend that I install the packages (ie "type 'sudo apt-get install package' to install")

rails -v && ruby -v && irb -v

Is there a way to make my terminal execute a command upon opening? Or, better yet, can anybody help explain the reason I have to run this line? I found an article that said I had to do that given my issue but it didn't explain why.


Solution

  • Assuming you're using the bash shell, then ~/.bash_profile will be sourced once (and only once) when you log in to the system but not each time you open a terminal window.

    The ~/.bashrc, however, will be sourced every time a new shell is opened (i.e. when you open a terminal window).

    So they are probably some environment variables settings in ~/.bash_profile which are required for ruby to run. Those settings should be moved to the ~/.bashrc file instead so they are defined in all shell instances.

    Alternatively, source ~/.bash_profile from your ~/.bashrc (this is at your own risk, it may have side-effects).