I need to add some line to nano .bash_profile in Terminal. Then:

1) I enter with this command line: nano .bash_profile

2) Add the line I need

3) now I don't know how to Save and Exit

I thought it is :w + enter. If this is correct I need some direction to use it.

  • I'm using control+O to save..but it keep asking 'File Name to Write: .bash_profile So how to make sure the 'edited' .bash_profile file is saved?
    – user23922
    Jun 13, 2012 at 4:45
  • 1
    Just press 'Enter' then
    – nohillside
    Jun 13, 2012 at 5:27

7 Answers 7


No, :w is a /usr/bin/vi command. Use the combination control+x to exit. You will be prompted to save the file if you have made unsaved changes.

Nano is intended to be a bit friendlier / simpler to new users than vi/vim or emacs which both cater to more power users that have spent time learning how to use them effectively.

To get started in nano - look for commands along the bottom of the window when nano is open. (^ stands for the control key)

^X      (F2)            Close the current file buffer / Exit from nano
^O      (F3)            Write the current file to disk
  • Keep in mind the shift key is needed for ^X and ^0 , tripped me up at first when we're used to being given commands in uppercase and the shift key explicitly stated as a shortcut in OSX.
    – Shwaydogg
    Apr 13, 2015 at 20:30
  • what is ^ sign? Pressing Shift + 6 and then X to create ^X seems not working! Got it, it seems ^ sign means Ctrl in linux world!
    – Hossein
    Oct 28, 2016 at 15:27
  • ctrl + ^ + O will do the trick for you.
    – panza
    Dec 10, 2016 at 18:18
  • 3
    @paranza ctrl and ⌃ is the same thing.
    – grg
    Jun 5, 2017 at 11:04

Per Apple's Support Article:

  1. To save the file, press Control-O.
  2. At the filename prompt, press Enter.
  3. To exit, press Control-X.

If you want to save the changes you've made, press Control+ O. To exit nano, type Control+ X. If you ask nano to exit from a modified file, it will ask you if you want to save it. Just press N in case you don't, or Y in case you do. It will then ask you for a filename. Just type it in and press Enter.

If you accidentally confirmed that you want to save the file but you actually don't, you can always cancel by pressing Control+ Cwhen you're prompted for a filename.


I just have the same question. after a lot of trail and error i learned that Nano is asking you to write the name of the "new conf file". Since you do not want a new file just hit enter indicating to nano that you want to keep the same name.

Basically you change the conf file, pres Ctrl + x and finally hit Enter (to indicate the same name). Good luck

  1. Enter nano .bash_profile (It will open the .bash_profile file in the nano editor)
  2. After making changes to the file use ControlX (to "exit")
  3. Then it asks for the changes to be made permanently and gives two options: Yes (or) No
  4. Press Y and press Enter to save the file

Hey I got something for you guys just enter ctrl + x and when it says to save press 'Y' if you want to save Then just press enter button Hope it works :)

  • How does this differ from the other four answers already describing the same solution?
    – nohillside
    Nov 28, 2018 at 12:36


sudo nano .bash_profile

To open your file instead. This will create your file if it doesn't exist, or open it for editing.

  • 4
    This is not the right place to use sudo -- that runs nano as root. It doesn't even really answer the question which is how do you save changes and exit nano. He already knows how to start nano.
    – Ian C.
    Aug 18, 2016 at 22:14
  • I know that it runs it as root. I had the same problem and doing the above fixed my problem. The accepted answer or an hour of research didn't. So unless the OP says this doesn't answer his question, I would disagree that it doesn't. Aug 18, 2016 at 22:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .