I am having a black screen issue on Linux after accidentally changing the $PATH variable

I find myself without access to the graphics system, the famous black screen. I can only access via tty, where I can enter my login and password and the following message appears:

Zorin OS 17.1 eita-thai tty2

eita-thai  login: thai

password:

Welcome to Zorin OS 17.1 (GNU/Linux 6.5.0-35-generic x86_64)


0 updates can be applied immediately
No new release found.


‘lesspipe’ command is available in the following locations
*/bin/lesspipe

*/urs/bin/lesspipe


The command was not found because 'usr/bin:/bin' is not included in the PATH environment variable.

lesspipe: command not found

‘dircolors’ command is available in the following locations
*bin/dircolors

*usr/bin/dircolors

The command was not found because '/bin:/usr/bin' is not included in the PATH environment variable.

dircolors: command not found

When I type:
echo $PATH
I receive in response:
/usr/local/bin/node:/sanp/bin
What actually I should see is something like a list of directories:
/home/thai/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

It looks like I accidentally replaced the entire list of directories with the node directory because my shell can't find/recognize commands. How can I restore the $PATH to its original configuration or how can I undo this change?

Do you remember what you did, exactly? Node.js should be already in your PATH when you install it.

What's the output of echo $PATH?

You can directly overwrite the variable inside your .bashrc file, at the end of the file add:

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

I was in the Visual Code terminal and it couldn't find the node I had already installed, showing something like:
sh: node: command not found
Using the Zorin terminal, I could type node-v and find the version number. So I started looking for tutorials that could help me with this issue and exactly what worked changed the $PATH.

When I type:
echo $PATH
I receive in response:
/usr/local/bin/node:/sanp/bin

How can I access the file .bashrc?
When I try using sudo find /-name .bashrc it appears that the

sudo command is not available in the following locations
*/bin/sudo
*/usr/bin/sudo
The command was not found because 'usr/bin:/bin' is not included in the PATH environment variable

In your home directory: $HOME/.bashrc.

These two are the same. However, if you've installed VSCode as a Flatpak (likely) then it will have restricted access to the file system, which is why it doesn't have the usual PATH variable set. You have two options:

  1. Install something called Flatseal to manage permissions for your Flatpak programs. You will find this in the Software Store, but I'm not sure exactly which permission you need to enable.

  2. Uninstall the Flatpak version and Install VSCode from their website instead, in order to avoid similar issues in the future (make a backup of your configuration files, etc). The .deb package format is the native format used by Zorin OS. Download it and run sudo dpkg -i whatever-the-package-is-called

Personally, I recommend option 2. To check if you've installed the Flatpak version run (after you've fixed the PATH) flatpak list to see all the packages installed in this format. And to uninstall use flatpak uninstall com.visualstudio.code.

When I type:
$HOME: /.bashrc

Appears as a response:
-bash: /home/thai/: It is a directory

I tried overwriting the variable inside the .bashrc file,as you said:

export PATH=$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

And when I type:
echo $PATH

Appears:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

Now how do I make it “record” this result? When I clear the screen with CTRL + D, and type:

echo $PATH
Appears again:
/usr/local/bin/node:/sanp/bin

Watch out for typos: $HOME/.bashrc

You need to make these changes inside this file, otherwise they only apply for the current shell session. Don't export it, either.

Alternatively, run this command:

echo 'PATH=$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' >> $HOME/.bashrc

This will add it immediately for you. Close the terminal, and next it should have loaded this.

After run:
echo 'PATH=$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' >> $HOME/.bashrc
(being careful with the spaces)
When I type again:
echo $PATH
The terminal returns me:
/usr/local/bin/node:/snap/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
That's right?
But when I type exit to close the terminal the initial error appears again

It looks right although it's strange that your can see the correct output right away without closing the terminal and re-open it.

This makes me think you are running this from VSCode, is that the case? If so, what if you open the terminal application itself and repeat the steps from there, close it and re-open it: does it retain the updated PATH?

What is the output now of this:

tail $HOME/.bashrc

This should print the last 10 lines of the file. It's okay (for now) if it has some repeated lines, this can be cleaned up later.

I'm using tty, it's the only thing I can do something.

My output is:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" #This loads nvm
[ -s "$NVM_DIR/bas_completion" ] && \. "$NVM_DIR/bash_completion" #This loads nvm bash_completion

PATH=$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PATH=$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

But now after restarting and press CTRL+ALT+F2, type login, password, still appears:

‘lesspipe’ command is available in the following locations
*/bin/lesspipe
*/urs/bin/lesspipe
The command was not found because 'usr/bin:/bin' is not included in the PATH environment variable.

lesspipe: command not found
‘dircolors’ command is available in the following locations
*bin/dircolors

*usr/bin/dircolors
The command was not found because '/bin:/usr/bin' is not included in the PATH environment variable.

dircolors: command not found

then run:
echo $PATH
The result is:
/usr/local/bin/node:/snap/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

Ok, let's try to remove it entirely and see if it picks up the global .bashrc file. It's not necessary to remove it entirely, just rename it to something else:

mv $HOME/.bashrc $HOME/.bashrc.bak

Although I suspect this is not really related to the $PATH variable; do you remember what instructions you followed? It would help to try to reverse them one at the time.

When I run this:

mv $HOME/.bashrc $HOME/.bashrc.bak

The errors that appeared immediately after logging in and entering the password have disappeared.

But when I run:
echo $PATH

I get:
/usr/local/bin/node:/snap/bin

But when I run:
$HOME/.bashrc

I get:
-bash: /home/thai/.bashrc: No such file or directory

And when I run:

tail $HOME/.bashrc

I get:

'tail' command is available in the following locations
*/bin/tail
*/usr/bin/tail
The command was not found because 'bin:/usr/bin' is not included in the PATH environment variable

Also I made the mistake of making this change late on a Friday night, I solved my problem with running the node in visual code but I only turned the machine back on on Monday and I didn't remember exactly what I had done.

I remember encountering this error:
-bash: node: command not found
making changes to the launch.json config file. (the debug settings in VSCode):
"runtimeExecutable": "/usr/local/bin/node"
but still not working. And I also remember using the terminal itself (not from vs code) to make sure the node's PATH was found, so I tried something like this:
[node.js - node: command not found - Stack Overflow](https://Node - Command not found (StackOverflow))

I fear that we may be focusing on the wrong issue here; the PATH variable has no impact on whether the operating system is able to boot into the graphical desktop, so something else must have changed. It looks like you tried to install NVM (Node Version Manager) but that has no impact on this either.

Would you be willing to re-install the OS from scratch? It might just be the fastest solution, as we're otherwise chasing ghosts that may or may not have something to do with this.

If you have important data you can still back it up to an external drive using the command line; I would suggest doing that anyway just in case something else we try breaks things further (hard to do at this point anyway, but just to be safe).

Let me know if you need help with that. Basically, when you plugin an external drive you can inspect where it's mounted at by running the command /usr/lib/lsblk. Note that since that the PATH variable is broken you need to specify the full location to the executable. This would show something like this:

NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda           8:0    0 931,5G  0 disk
└─sda1        8:1    0 931,5G  0 part /media/zenzen/TOSHIBA EXT
zram0       251:0    0   7,7G  0 disk [SWAP]
nvme0n1     259:0    0 232,9G  0 disk
├─nvme0n1p1 259:1    0   300M  0 part /boot/efi
└─nvme0n1p2 259:2    0 232,6G  0 part /

In my case, my Toshiba external drive is mounted at /media/zenzen/TOSHIBA EXT. You can then copy files with /usr/bin/cp to copy the files you want to back up to the external drive. To copy entire directories instead of individual files, pass the -r flag: /usr/bin/cp -r


For now, back to the PATH issue:

We've removed your own .bashrc profile from the equation so this is all that's left. It makes sense that it shows something but it's unexpected that it's only this; I would expect to show all the usual directories that we've tried to include manually.

Let's try once again to re-create the .bashrc file. You can use nano to create the file from the terminal:

/usr/bin/nano $HOME/.bashrc

And write just the following lines.

. /etc/bash.bashrc
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

Save the changes by pressing Ctrl+O and exit nano by pressing Ctrl+X. Now you can logout and log back in again, hopefully this has amended the problem (at least temporarily).

My next step would be to try re-installing the graphical desktop in case it was removed or broken somehow. As I said, none of the above has any relation with the graphical desktop, which points to something else more drastic broken.

sudo apt install --reinstall zorin-os-desktop

Or, if this produces no results or claims that this package is not installed:

sudo apt install zorin-os-desktop

Thanks for your help, patience, and time! I was able to restore my path to access sudo and reinstall Zorin without losing my files.

1 Like