### METHOD 1 - Via Command line ###
# If you have never set it before
echo "export EDITOR='new_program'" >> ~/.bashrc
echo "export VISUAL='new_program'" >> ~/.bashrc
source ~/.bashrc
### METHOD 2 - Via Command line ###
# If you are changing an existing setting
sed -i 's/export EDITOR='old_program'/export EDITOR='new_program'/' ~/.bashrc
sed -i 's/export VISUAL='old_program'/export VISUAL='new_program'/' ~/.bashrc
source ~/.bashrc
### METHOD 3 - Via Text Editor ###
# You can also change the setting by opening ~/.bashrc in
# your favourite text editor then add/update the lines
export EDITOR='new_program'
export VISUAL='new_program'
# Exit & Save File then run below command
source ~/.bashrc
# Short answer:
# In Ubuntu, run select-editor which will create a ~/.selected_editor file
# with your preferred editor
select-editor