4

I have changed my environment variables before now. When I am trying to use the following command:

sudo vi /etc/environment

I am getting following warning/error and I am confused about what to do next.

E325: ATTENTION
Found a swap file by the name "/etc/.environment.swp"
      owned by: root   dated: Wed Apr 18 15:03:44 2018
     file name: /etc/environment
      modified: no
     user name: root   host name: my-desktop
    process ID: 6410
     [not usable on this computer]
While opening file "/etc/environment"
         dated: Wed Apr 18 14:49:02 2018

(1) Another program may be editing the same file.  If this is the 
case,
be careful not to end up with two different instances of the same
file when making changes.  Quit, or continue with caution.
(2) An edit session for this file crashed.
If this is the case, use ":recover" or "vim -r /etc/environment"
to recover the changes (see ":help recovery").
If you did this already, delete the swap file "/etc/.environment.swp"
to avoid this message.
"/etc/environment" 6 lines, 389 characters
Press ENTER or type command to continue

So can someone please explain to me what to do next and what this message really means?

UPDATE: I tried to do as suggested .I pressed e and it opened the environment file then I pressed i to edit it and changed my nodejs version (initially it was 9.x and I made it 8.x) then I pressed Esc and then shift+; and then wq|x after that I finally pressed Enter and it closes the vi editor after that again I ran the same command but it gave me same error but with further update stating NEWER than swap file!

Full message as follows:

E325: ATTENTION
Found a swap file by the name "/etc/.environment.swp"
      owned by: root   dated: Wed Apr 18 15:03:44 2018
     file name: /etc/environment
      modified: no
     user name: root   host name: my-desktop
    process ID: 6410
     [not usable on this computer]
 While opening file "/etc/environment"
         dated: Mon May 14 16:53:13 2018
  NEWER than swap file!

(1) Another program may be editing the same file.  If this is the 
case,
be careful not to end up with two different instances of the same
file when making changes.  Quit, or continue with caution.
(2) An edit session for this file crashed.
If this is the case, use ":recover" or "vim -r /etc/environment"
to recover the changes (see ":help recovery").
If you did this already, delete the swap file "/etc/.environment.swp"
to avoid this message.
"/etc/environment" 7 lines, 390 characters
Press ENTER or type command to continue

So don't know how to resolve it!

1
  • You should delete the .{yourfile}.{your extension}.swp file to not get this error again You had opened another instance of this file and did not save so you need to delete the swap file to not see this error pop up. Nov 15, 2018 at 14:23

1 Answer 1

5

It means you or another user has already started editing the file and there are unsaved changes to it. You probably opened the file, began editing it, and then exited Vi without writing.

The instructions tell you what to do.

You can either press r to recover the file and you will see the version with the unsaved changes. Make your edits.

If you don't want to recover the unsaved changes, press q to quit and delete the file mentioned in the message

sudo rm /etc/.environment.swp

Then you can open it again and find the last saved version.

When you want to save your changes and exit press esc and type :wq.

But, are you sure you need to edit /etc/environment? Consider whether you had better use a per-user config file such as ~/.profile instead.

3
  • thanks for replying but I tried what you suggested but it didn't help ,I have updated my post to show what happened next . I am the only user of my Ubuntu so no other user .I don't have much idea about ~/.profile as I am a beginner. I had installed nodejs 8.x version ,initially it was 9.x so wanted to update the path ,that's why tried to edit /etc/environment .So can we update path through ~/.profile ??
    – user716691
    May 14, 2018 at 11:36
  • Ooops sorry, I've edited. Yes, you can and should adjust PATH in ~/.profile. I recommend not changing the PATH in /etc/environment, and undoing any changes you made to it already, because you can't return to the default PATH unless you remember what was in it if you edit that file.
    – Zanna
    May 14, 2018 at 11:50
  • thank you ,now its done ,and as you suggested I will check how to adjust PATH through ~/.profile :)
    – user716691
    May 14, 2018 at 12:03

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.