.bashrc: Permission denied

150,565

Solution 1

.bashrc is not meant to be executed but sourced. Try this instead:

. ~/.bashrc

or, equivalently

source ~/.bashrc

See the reference about the . (aka source) builtin.


Note that if what you're looking for is to restart your Bash session after modifying your ~/.bashrc file, you might as well use:

exec bash

That will replace your current Bash session (thanks to exec) by a new session.

Solution 2

If you want to edit that file (or any file in generally), you can't edit it simply writing its name in terminal. You must to use a command to a text editor to do this. For example:

nano ~/.bashrc

or

gedit ~/.bashrc

And in general, for any type of file:

xdg-open ~/.bashrc

Writing only ~/.bashrc in terminal, this will try to execute that file, but .bashrc file is not meant to be an executable file. If you want to execute the code inside of it, you can source it like follow:

source ~/.bashrc

or simple:

. ~/.bashrc 
Share:
150,565
srgg6701
Author by

srgg6701

Web-developer

Updated on July 25, 2022

Comments

  • srgg6701
    srgg6701 almost 2 years

    I try to work with a project in vagrant. I have made the command vagrant ssh, and connected to VM. Now I need to edit .bashrc file to set path to the source code. But first I couldn't find that file. So I googled and find that the way is call command ~/.bashrc. But doing this I get message, that I have no access to it:

    [vagrant@nupic-vagrant:~]$ ~/.bashrc
    -bash: /home/vagrant/.bashrc: Permission denied
    

    So what to do now?

    UPD. I can't find the .bashrc file. When I try to make command ls -a I get following:

    [vagrant@nupic-vagrant:~]$ ls -a
    .              .bash_logout   cleanup.sh   sshd.sh        .veewee_params
    ..             .bash_profile  minimize.sh  vagrant.sh     .veewee_version
    .bash_history  .bashrc        .ssh         .vbox_version  .zsh_profile
    [vagrant@nupic-vagrant:~]$ locate .bashrc
    /etc/skel/.bashrc
    /home/vagrant/.bashrc
    /var/chef/backup/etc/skel/.bashrc.chef-20130614181911
    /var/chef/backup/home/vagrant/.bashrc.chef-20130614181912
    [vagrant@nupic-vagrant:~]$
    

    But only the place where I can find some of those files is the directory where cygwin is installed. Pls, see illustrations, they reflect relations between directories vagrant and cygwin. enter image description here