112

I've been trying to install Android developer tools on Eclipse, and I followed the information in this video.

Like the video said, I added the following two lines of code to the .bashrc file:

export PATH=$(PATH):-/android-sdk/tools/
export PATH=$(PATH):-/android-sdk/platform-tools/

It seems, however, that this did not help me to install the Android files on Eclipse, as I am still having problems with that. What's more, it seems that I can't make any command in the terminal without getting a major error now! Every time I try to make a command in the terminal I get the following message:

The command could not be located because '/usr/bin' is not included in the PATH environment variable.

Is there away to restore .bashrc to its default?

2
  • 1
    Root cause: The $(PATH) should in fact be $PATH
    – Elder Geek
    Mar 31, 2017 at 17:14
  • $ nano .bashrc Jun 16, 2022 at 10:05

4 Answers 4

191

Idea: There exist backup copies of .bashrc, .profile etc. in /etc/skel/. So one could replace a corrupt .bashrc simply by overwitting from there.

Caution: if you replace the .bashrc file with a fresh one, it will remove any other modification(s) you have made to it. For example, one could add aliases, custom function or PATH in .bashrc. When you replace the file, all those modifications will be lost. Better you can keep a copy of your modified .bashrc before replacing it. Later, you can carefully extract the required part from it. To keep a backup copy of your modified .bashrc in your home directory with name my_bashrc use the following in a terminal,

/bin/cp ~/.bashrc ~/my_bashrc

Why /bin/cp: In case if you have messed with your $PATH variable when changed ~/.bashrc all the executable will be unavailable from your terminal and cp will not work anymore. So it is recommended to call cp with its full path as /bin/cp while you are trying to copy something with corrupt ~/.bashrc.

Finally, use the following command in your terminal to replace the ~/.bashrc with a fresh copy,

/bin/cp /etc/skel/.bashrc ~/

It will replace your corrupt ~/.bashrc with a fresh one. After that, you need to source the ~/.bashrc so that the change takes place immediately, write in the terminal,

. ~/.bashrc

or,

source ~/.bashrc

or, if that does not work you can close the terminal and open it again.

13
  • Thank you for the response! For some reason I am still getting the error message
    – nanananana
    Jan 12, 2014 at 20:04
  • 2
    what is the exact error message?
    – sourav c.
    Jan 13, 2014 at 2:08
  • Command 'cp' is available in '/bin/cp' The command could not be located because '/bin' is not included in the PATH environment variable. cp: command not found
    – nanananana
    Jan 13, 2014 at 13:23
  • what is the output of echo $PATH?
    – sourav c.
    Jan 13, 2014 at 13:26
  • 4
    Note, this is essentially an overkill solution and will remove any other modification that you have done to the file.
    – Braiam
    May 9, 2014 at 0:39
14

If you can't get a working shell

Via the file browser

  • Open the file browser, go to the home directory, press CtrlH so that hidden files are shown. Edit .bashrc as needed.
  • Open the file browser, go to /etc/skel, press CtrlH so that hidden files are shown. Copy .bashrc to your home folder to restore it to the default.

Via the run menu

  • Press AltF2, type gedit .bashrc, press Enter. Edit as needed.
  • Press AltF2, use the command /bin/cp /etc/skel/.bashrc ~/ as given in souravc's answer to restore it to the default.

Via the terminal

  • Open the terminal, and ignore that you don't have a shell. Go to EditPreferencesProfiles:

    enter image description here

  • Either create a new profile, or edit the current profile, to change the command:

    enter image description here

    Use either /bin/bash --norc or /bin/bash --rcfile=/etc/skel/.bashrc.

  • Start a new tab (with the custom profile, if you created one). Use the working shell as needed.
  • Delete the custom profile, or uncheck the custom command option if you edited the default profile, once you're done.

If you have SSH

Run SSH with a custom command, which should help you bypass the .bashrc:

ssh -t <host> dash

The dash shell (aka /bin/sh) is minimal, but sufficient for restoring the .bashrc.

If you can't get a GUI and don't have SSH

Boot into recovery mode (How do I boot into recovery mode?), which will get you a root shell. Look in /home for your user's home directory.

9

Via the TTY

You can enter the TTY by pressing ctrl+alt+f1 where you have to login with your user-name and your password. ctrl+alt+f7 will bring you back to your GUI later.

Now copy the existing raw .bashrc from /etc/skel to your home directory by

cp /etc/skel/.bashrc ~/

Maybe even bring the rest over if you're not sure if your .profile was changed too.

cp /etc/skel/.profile ~/

Now to get the .bashrc to have immediate effect you might want to source it with:

source ~/.bashrc

If you did replace your .profile as well you need to reboot to make it take effect.

1
  • This solution works for me. Thanks :) Apr 6, 2021 at 7:17
5

I tried the above answers, but for some reason my /etc/skel/ directory did not have the correct files in it.

I found a copy of the default ~/.bashrc file on this GitHub Gist by Mario Bonales. The full script is copied here for completeness.

# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
[ -z "$PS1" ] && return

# don't put duplicate lines in the history. See bash(1) for more options
# ... or force ignoredups and ignorespace
HISTCONTROL=ignoredups:ignorespace

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
    xterm-color) color_prompt=yes;;
esac

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
    # We have color support; assume it's compliant with Ecma-48
    # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
    # a case would tend to support setf rather than setaf.)
    color_prompt=yes
    else
    color_prompt=
    fi
fi

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    ;;
*)
    ;;
esac

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    alias ls='ls --color=auto'
    #alias dir='dir --color=auto'
    #alias vdir='vdir --color=auto'

    alias grep='grep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias egrep='egrep --color=auto'
fi

# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'

# Add an "alert" alias for long running commands.  Use like so:
#   sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
    . /etc/bash_completion
fi
1

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