简体   繁体   English

我在哪里可以找到 Mac 上的 bashrc 文件?

[英]Where do I find the bashrc file on Mac?

Hello I am following this page .. I'm installing Python onto my mac so that I can set up a Django / Eclipse development environment.您好,我正在关注此页面.. 我正在将 Python 安装到我的 Mac 上,以便我可以设置Django / Eclipse开发环境。 However I am not too sure how to go about executing this step:但是我不太确定如何执行此步骤 go:

  • The script will explain what changes it will make and prompt you before the installation begins.该脚本将解释它将进行哪些更改,并在安装开始前提示您。
  • Once you've installed Homebrew, insert the Homebrew directory at the top of your PATH environment variable.安装 Homebrew 后,将 Homebrew 目录插入 PATH 环境变量的顶部。
  • You can do this by adding the following line at the bottom of your ~/.bashrc file您可以通过在~/.bashrc 文件底部添加以下行来执行此操作
  • export PATH=/usr/local/bin:$PATH导出 PATH=/usr/local/bin:$PATH

Where do I find the bashrc file on my mac and where do I find the homebrew directory?我在哪里可以找到我的 mac 上的 bashrc 文件,我在哪里可以找到 homebrew 目录?

I am running a macbook pro with OS 10.8.5 .我正在运行带有OS 10.8.5macbook pro。

The .bashrc file is in your home directory. .bashrc 文件位于您的主目录中。

So from command line do:所以从命令行做:

cd
ls -a

This will show all the hidden files in your home directory.这将显示主目录中的所有隐藏文件。 "cd" will get you home and ls -a will "list all". “cd”会让你回家,ls -a 会“列出所有”。

In general when you see ~/ the tilda slash refers to your home directory.通常,当您看到 ~/ 时,tilda 斜杠指的是您的主目录。 So ~/.bashrc is your home directory with the .bashrc file.所以 ~/.bashrc 是包含 .bashrc 文件的主目录。

And the standard path to homebrew is in /usr/local/ so if you:自制软件的标准路径在 /usr/local/ 中,所以如果您:

cd /usr/local
ls | grep -i homebrew

you should see the homebrew directory (/usr/local/homebrew).您应该会看到自制软件目录 (/usr/local/homebrew)。 Source来源

Yes sometimes you may have to create this file and the typical format of a .bashrc file is:是的,有时您可能需要创建此文件,.bashrc 文件的典型格式是:

# .bashrc

# User specific aliases and functions
. .alias
alias ducks='du -cks * | sort -rn | head -15'

# Source global definitions
if [ -f /etc/bashrc ]; then
    . /etc/bashrc
fi

PATH=$PATH:/home/username/bin:/usr/local/homebrew
export PATH

If you create your own .bashrc file make sure that the following line is in your ~/.bash_profile如果您创建自己的 .bashrc 文件,请确保以下行在您的 ~/.bash_profile 中

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi

I would think you should add it to ~/.bash_profile instead of .bashrc , (creating .bash_profile if it doesn't exist.) Then you don't have to add the extra step of checking for ~/.bashrc in your .bash_profile我认为您应该将它添加到~/.bash_profile而不是.bashrc ,(如果它不存在,则创建.bash_profile 。)然后您不必在~/.bashrc中添加检查~/.bashrc的额外步骤.bash_profile

Are you comfortable working and editing in a terminal?您是否习惯在终端中工作和编辑? Just in case, ~/ means your home directory, so if you open a new terminal window that is where you will be "located".以防万一, ~/表示您的主目录,因此如果您打开一个新的终端窗口,您将在该窗口“定位”。 And the dot at the front makes the file invisible to normal ls command, unless you put -a or specify the file name.前面的点使文件对普通ls命令不可见,除非您输入-a或指定文件名。

Check this answer for more detail.检查此答案以获取更多详细信息。

In my macOS Monterey version, zsh is the default terminal shell. zsh executes ~/.zshrc every time the terminal is opened.在我的 macOS Monterey 版本中,zsh 是默认终端 shell。每次打开终端时,zsh 都会执行 ~/.zshrc。

vi ~/.zshrc
#Add your path export to .zshrc
PATH=/usr/local/bin:$PATH 

Now, when you open the terminal, the path will be set correctly.现在,当您打开终端时,路径将被正确设置。

On your Terminal:在您的终端上:

  • Type cd ~/ to go to your home folder.键入cd ~/转到您的主文件夹。

  • Type touch .bash_profile to create your new file.输入touch .bash_profile来创建你的新文件。

  • Edit .bash_profile with your code editor (or you can just type open -e .bash_profile to open it in TextEdit).使用您的代码编辑器编辑.bash_profile (或者您可以输入open -e .bash_profile在 TextEdit 中打开它)。
  • Type . .bash_profile键入. .bash_profile . .bash_profile to reload .bash_profile and update any functions you add. . .bash_profile重新加载.bash_profile并更新您添加的任何功能。

~/.bashrc is already a path to .bashrc . ~/.bashrc已经是.bashrc的路径。

If you do echo ~ you'll see that it's a path to your home directory.如果你执行echo ~你会看到它是你的主目录的路径。

Homebrew directory is /usr/local/bin . Homebrew 目录是/usr/local/bin Homebrew is installed inside it and everything installed by homebrew will be installed there. Homebrew 安装在它里面,homebrew 安装的所有东西都将安装在那里。

For example, if you do brew install python Homebrew will put Python binary in /usr/local/bin .例如,如果您执行brew install python Homebrew 会将 Python 二进制文件放在/usr/local/bin

Finally, to add Homebrew directory to your path you can run echo "export PATH=/usr/local/lib:$PATH" >> ~/.bashrc .最后,要将 Homebrew 目录添加到您的路径,您可以运行echo "export PATH=/usr/local/lib:$PATH" >> ~/.bashrc It will create .bashrc file if it doesn't exist and then append the needed line to the end.如果它不存在,它将创建.bashrc文件,然后将所需的行附加到末尾。

You can check the result by running tail ~/.bashrc .您可以通过运行tail ~/.bashrc来检查结果。

在某些系统上,您可以通过编辑而不是 .bashrc 文件来编辑特定于您的配置文件:

sudo nano /etc/profile

The .bash_profile for macOS is found in the $HOME directory. macOS 的 .bash_profile 位于$HOME目录中。 You can create the file if it does not exit.如果文件没有退出,您可以创建该文件。 Sublime Text 3 can help. Sublime Text 3 可以提供帮助。

  • If you follow the instruction from OS X Command Line - Sublime Text to launch ST3 with subl then you can just do this如果您按照OS X 命令行 - Sublime Text 中的说明使用subl启动 ST3,那么您可以这样做

    $ subl ~/.bash_profile
  • An easier method is to use open一个更简单的方法是使用open

     $ open ~/.bash_profile -a "Sublime Text"

Use Command + Shift + .使用Command + Shift + in Finder to view hidden files in your home directory.在 Finder 中查看主目录中的隐藏文件。

Open Terminal and execute commands given below.打开终端并执行下面给出的命令。

cd /etc
subl bashrc

subl denotes Sublime editor. subl 表示 Sublime 编辑器。 You can replace subl with vi to open bashrc file in default editor.您可以用vi替换subl以在默认编辑器中打开 bashrc 文件。 This will workout only if you have bashrc file, created earlier.只有当你有之前创建的 bashrc 文件时,这才会锻炼。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM