No bashrc file in my home directory

Here is what I noted down from my lecture:

  • Find file .bashrc in your home directory
  • do vi .bashrc
  • When you put an application folder somewhere, make sure that its address is in the path variable.

The problem is that I do not have a .bashrc file in my home directory. There is only a .bash_history file in my home.

If i go to the root, there is a etc/bash.bashrc file there but what i think is that it will make changes for all users and not just for me. I want to add this path just for myself. It shouldn't effect others. Also there is no $PATH variable in that bashrc file so I am even more confused.


Solution 1:

Don't forget it is a hidden file inside your home directory (you would not be the first to do a ls -l and thinking it is not there).

Do following ...

ls -la ~/ | more

There should be a .bashrc on the first page. If not just create it with

vi ~/.bashrc

And simply write following line into it.

PATH=$PATH:~/bin

OR Most of the distributions keep a standard .bashrc file in /etc/skel/ You can copy it to home directory.

$cp /etc/skel/.bashrc ~

Solution 2:

Most distributions keep a standard .bashrc file in /etc/skel/ you can just copy to your home dir. Otherwise you could just make a new empty .bashrc file in your home dir.

Solution 3:

Create Your Own Startup File for Interactive Shells

About Bash Startup Files

From the INVOCATION section of man 1 bash says:

When an interactive shell that is not a login shell is started, bash reads and executes commands from /etc/bash.bashrc and ~/.bashrc, if these files exist.

Note that these startup files are optional; Bash doesn't require them. Bash also differentiates between login shells and interactive shells. An interactive shell is defined thus:

An interactive shell is one started without non-option arguments and without the -c option whose standard input and error are both connected to terminals (as determined by isatty(3)), or one started with the -i option.

Many distributions source one type of startup file from the other, but some don't, so this issue can be difficult to address canonically. You need to examine all your startup files to see how and when your ~/.bashrc will be invoked on your system.

Creating Your Per-User Interactive Shell Startup File

If you're simply missing a user-specific ~/.bashrc file, just create one. This will be invoked by Bash for non-login shells (e.g. shells started without the --login flag), or whenever you force the shell to be interactive by invoking it with the -i flag.