bash 在终端中使用 subl 命令的问题:“找不到命令”和“没有这样的文件或目录”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10892368/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 22:11:44  来源:igfitidea点击:

Problems using subl command in terminal: "Command not found" & "No such file or directory"

bashterminalsublimetext2

提问by Ralitza

I want to apologize in advance that this is a newbie question! I've spent the last 2 hours trying to find a solution.

我想提前道歉,这是一个新手问题!我花了过去 2 个小时试图找到解决方案。

I have two problems (I'm sure related).

我有两个问题(我确定相关)。

Background:

背景:

This is what my $PATH looks like:

这是我的 $PATH 的样子:

/Users/Sponsi/.rvm/gems/ruby-1.9.3-p194/bin:/Users/Sponsi/.rvm/gems/ruby-1.9.3-p194@global/bin:/Users/Sponsi/.rvm/rubies/ruby-1.9.3-p194/bin:/Users/Sponsi/.rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin

/Users/Sponsi/.rvm/gems/ruby-1.9.3-p194/bin:/Users/Sponsi/.rvm/gems/ruby-1.9.3-p194@global/bin:/Users/Sponsi/.rvm/ rubies/ruby-1.9.3-p194/bin:/Users/Sponsi/.rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/ git/bin:/usr/X11/bin

Problem #1

问题#1

I am trying to use the command-line command "subl" to launch Sublime Text 2 on OSX.

我正在尝试使用命令行命令“subl”在 OSX 上启动 Sublime Text 2。

I entered the following command: "ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/subl

我输入了以下命令:“ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/subl

It only halfway worked - when I enter "subl" I get "Command not found". But when I re-enter the command above it says "Already exists."

它只成功了一半 - 当我输入“subl”时,我得到“找不到命令”。但是当我重新输入上面的命令时,它显示“已经存在”。

I searched online and found a (somewhat) fix. I added the following to my .bashrc:

我在网上搜索并找到了一个(有点)修复。我在 .bashrc 中添加了以下内容:

echo 'export PATH="./bin:$PATH"' >> ~/.bashrc 
source ~/.bashrc

Using the command "subl" does work but only temporarily. If I exit terminal or switch to another directory it stops working (bringing me into problem #2, see below.)

使用命令“subl”确实有效,但只是暂时的。如果我退出终端或切换到另一个目录,它就会停止工作(让我陷入问题 #2,见下文。)

Problem # 2:

问题#2:

When I try to pull up a file under another directory using the command "subl" I get "-bash: ./bin/subl: No such file or directory" I confirmed the file I want to edit does exist.

当我尝试使用命令“subl”在另一个目录下拉出一个文件时,我得到“-bash:./bin/subl:没有这样的文件或目录”我确认我想要编辑的文件确实存在。

BTW, I am following the Ruby tutorial found @ http://ruby.railstutorial.org/ruby-on-rails-tutorial-book

顺便说一句,我正在关注@ http://ruby.railstutorial.org/ruby-on-rails-tutorial-book的 Ruby 教程

Thank you so much for your time!

非常感谢您的参与!

回答by isanjosgon

Run each command in the Terminal (in this order):

在终端中运行每个命令(按此顺序):

$ sudo rm -rf /usr/local/bin/subl
$ sudo ln -s /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl /usr/local/bin
$ subl .

This should work!

这应该有效!

Note:First you should check that your sublime's app is in Applications folder and it's name is Sublime Text 2, if not, you should change the name in the second command and type the name of sublime's app.

注意:首先您应该检查您的 sublime 的应用程序是否在 Applications 文件夹中,并且它的名称是 Sublime Text 2,如果不是,您应该在第二个命令中更改名称并键入 sublime 的应用程序的名称。

回答by Bob Walsh

if you are using RVM, do this:

如果您使用的是 RVM,请执行以下操作:

ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/.rvm/bin/subl

回答by Rahul Arora

For El Captain or later OS:

对于 El Captain 或更高版本的操作系统:

In El Capitan, you are not allowed to write to /usr/bin, but writing to /usr/local/bin is ok. By default, /usr/local/bin should also be in your path variable.

El Capitan 中,您不能写入 /usr/bin,但可以写入 /usr/local/bin。默认情况下, /usr/local/bin 也应该在你的路径变量中。

For Sublime Text 3

对于崇高的文本 3

sudo rm /usr/local/bin/subl
sudo ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl

For Sublime Text 2

对于Sublime Text 2

sudo rm /usr/local/bin/subl
sudo ln -s /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl

回答by Rimian

I stuck mine in /usr/bin

我把我的卡在 /usr/bin

sudo ln -s /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl /usr/bin

sudo ln -s /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl /usr/bin

or for Sublime 3 or later

或用于 Sublime 3 或更高版本

sudo ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/bin

sudo ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/bin

It's already in $PATH

它已经在 $PATH 中

回答by Naguib Ihab

If you're using Sublime Text 3you need to adjust the commands in isanjosgon's answer:

如果您使用的是Sublime Text 3,则需要调整 isanjosgon 的答案中的命令:

$ sudo rm -rf /usr/local/bin/subl
$ sudo ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/
$ subl .

回答by nuin

I had the same problem, on a new Mac recently configured. I had RVM installed before oh-my-zsh and sublime text and I was running into the same problems. I tried different locations on the path

我在最近配置的新 Mac 上遇到了同样的问题。我在 oh-my-zsh 和 sublime text 之前安装了 RVM,但遇到了同样的问题。我在路径上尝试了不同的位置

/usr/bin
/usr/local/bin

all of them in the path. What worked for me was to get rid of the quotes on the command line running as

他们都在路上。对我有用的是摆脱命令行上运行的引号

sudo ln -s /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl /usr/bin/subl

回答by Sean Crockett

Regarding your first problem, could it be that you don't have a bin directory set up under you home directory (i.e., ~/bin)? To check this, type the following:

关于您的第一个问题,可能是您的主目录(即~/bin)下没有设置bin目录吗?要检查这一点,请键入以下内容:

cd ~/
ls -l

If there is no bin directory, type the following:

如果没有 bin 目录,请键入以下内容:

mkdir bin

Once you've created the directory, retype the following:

创建目录后,重新键入以下内容:

subl --help

Hopefully that takes care of the issue

希望能解决这个问题

回答by Jeremy

Edit your ~/.bashrcfile to contain this line at the end of it:

编辑您的~/.bashrc文件以在其末尾包含此行:

export PATH="$HOME/bin:$PATH

Notice the ~is there instead of the .from your example? The ~signifies your home directory, which is where your .bashrcfile lives. The dot signifies the currentdirectory of your terminal window.

请注意~那里的而不是.您示例中的 ?在~表示你的home目录,这是你的地方.bashrc文件的生活。点表示终端窗口的当前目录。

Once you've made the change, close your terminal window and re-open it. Then sublshould be avaiable on the PATH.

完成更改后,关闭终端窗口并重新打开它。然后subl应该在 PATH 上可用。

回答by Pankaj Agrawal

You can also create new alias if you want like

如果你愿意,你也可以创建新的别名

alias subl="/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl"

alias subl="/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl"

回答by Raj

$ alias subl="/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl"

$ subl .This works! :D

$ subl .这有效!:D