'How to run a command automatically after each reboot

I currently have Ubuntu 16.04 installed on my virtual box. I installed Ruby and Rails by RVM. After that I tried

$ rails

The terminal said

The program `rails` is currently not installed. You can install it by typing:
 sudo apt install ruby-railties

I solve this problem by typing

$ source ~/.rvm/scripts/rvm

Credits here

However, once I reboot the virtual machine, everything I did with source will lose and I need to re-enter

 $ source ~/.rvm/scripts/rvm

I also have some similar cases I need to do on every reboot. So is there any solution can make those command be run automatically each time?



Solution 1:[1]

Depending of which implementation of cron you're using it's possible to run jobs only after reboots, for example:

@reboot source ~/.rvm/scripts/rvm

Again. before editing your crontab make sure your cron implementation supports @reboot flag.

Another option is to include all your scripts in /etc/rc.local

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tiago Almeida