macOS 10.15 Terminal - unlink gets "Operation not permitted" - terminal

zsh; Terminal has Full Disk Access permission in System Preferences.
/usr/bin % ls -alF python
lrwxr-xr-x 1 root wheel 75 Jul 12 11:48 python# -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
/usr/bin % sudo unlink python
Password:
unlink: python: Operation not permitted
/usr/bin %
EDIT by OP to add this terminal transcript:
~ % whence python
/usr/bin/python
~ % echo $PATH
/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Users/brec/.rvm/bin
~ % ls -alF /usr/local/bin/python
lrwxr-xr-x 1 brec admin 24 Dec 11 10:45 /usr/local/bin/python# -> /usr/local/bin/python3.8
~ % python
WARNING: Python 2.7 is not recommended.
NOTE: /usr/local/bin/python3.8 does not exist.

On recent macOS versions, System Integrity Protection (SIP) prevents modification of files in several locations, including /usr/bin. Because some parts of macOS use Python, you cannot modify the symlink at /usr/bin/python - if you did, it might break some parts of the OS which depend on that specific version of Python. You cannot modify SIP-protected files even as root.
Your best bet is to install a separate version of Python and make sure your PATH environment variable is set accordingly.

I unlinked /usr/local/bin/python and then created a soft link /usr/local/bin/python to the version of python I want the python command to execute.

Related

Does `Fish` change the order of $PATH? How to avoid that

fish --version
> fish, version 3.0.2
uname -a
> Darwin Jerrys-MacBook.local 18.6.0 Darwin Kernel Version 18.6.0: Thu Apr 25 23:16:27 PDT 2019; root:xnu-4903.261.4~2/RELEASE_X86_64 x86_64
echo $TERM
> xterm-256color
I have compare my $PATH in bash and fish shell, the order of rvm changed, which cause which pod become different(i used rvm to manage ruby).
How can I make them same order ?
By the way,
I have include all my setting in .bashrc and load it by source ~/.bashrc in .bash_profile, noting in .prfile
And I have nothing in ~/.config/fish/config.fish
The begin character of x,~,=,> just I added mark to compare easily.
----- echo $PATH
=:~/.rvm/gems/ruby-2.2.9/bin
=:~/.rvm/gems/ruby-2.2.9#global/bin
=:~/.rvm/rubies/ruby-2.2.9/bin
X=:/opt/local/bin
X=:/opt/local/sbin
=:~/.nvm/versions/node/v8.11.3/bin
~:/usr/local/bin
~:/usr/bin
~:/bin
~:/usr/sbin
~:/sbin
>:/usr/local/share/dotnet
>:/opt/X11/bin
>:/Library/Frameworks/Mono.framework/Versions/Current/Commands
X-:~/.rvm/bin
X-:~/.local/bin
X-:/usr/local/Cellar/aria2/1.33.1/bin
X-:~/Documents/code/flutter/sdk/flutter/bin
X-:~/Documents/code/flutter/sdk/flutter/bin/cache/dart-sdk/bin
X-:~/Documents/code/flutter/sdk/flutter/.pub-cache/bin
------ fish & echo $PATH
~/usr/local/bin
~/usr/bin
~/bin
~/usr/sbin
~/sbin
>/opt/X11/bin
>/usr/local/share/dotnet
>/Library/Frameworks/Mono.framework/Versions/Current/Commands
=~/.rvm/gems/ruby-2.2.9/bin
=~/.rvm/gems/ruby-2.2.9#global/bin
=~/.rvm/rubies/ruby-2.2.9/bin
X=/opt/local/bin
X=/opt/local/sbin
=~/.nvm/versions/node/v8.11.3/bin
X-~/.rvm/bin
X-~/.local/bin
X-/usr/local/Cellar/aria2/1.33.1/bin
X-~/Documents/code/flutter/sdk/flutter/bin
X-~/Documents/code/flutter/sdk/flutter/bin/cache/dart-sdk/bin
X-~/Documents/code/flutter/sdk/flutter/.pub-cache/bin
Here is a simple workaround from this PR,
# Download patched config
curl -O https://raw.githubusercontent.com/fish-shell/fish-shell/e18354bc6ef937e2e663fc098cc51a2546d4d2d0/share/config.fish
# Install config
mv config.fish /usr/local/share/fish/
here how i solved it (using fish only as interactive on top of my zsh):
in .zshrc:
export ZSHPATH="$PATH"
fish
in .config/fish/config.fish
set PATH $ZSHPATH $PATH
To be simple, download & install the version fish-2.7.1.pkg which don't have this bug on Mac.
According to code commit, next version fish-3.1.0 may fix this bug.

Not getting graphics even when reinstalled Ocaml (Mac OS X)?

Following this post I installed brew and then reinstalled ocaml to include graphics:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew cask install xquartz
brew reinstall ocaml --with-x11
But after restarting my computer, when I tried to run an ocaml program that used graphics I got the error
Error: Cannot find file /Users/.../.opam/4.03.0/lib/ocaml/graphics.cma
The post also said:
Finally remember to check that the instance of ocaml that is running
is the one in /usr/local/Cellar/objective-caml/x.yy.z[_w]/bin, and
if it isn't then prepend that url to your PATH environment
variable.
How do I do check the instance of ocaml that is running? And what does the poster mean by "prepending that url to your PATH environment"?
I've tried changing my directory to that path, but I get an error:
$ cd /usr/local/Cellar/objective-caml/
-bash: cd: /usr/local/Cellar/objective-caml/: No such file or directory
If someone could please tell me what I need to do to get graphics.cma working that would be great!
UPDATES:
I've tried creating .bashrc and putting in
alias ocaml="/usr/local/Cellar/ocaml/4.04.0/bin/ocaml”
Yet with no avail...I'm quite lost on what to do. If anyone could give me an inkling of what to do that would be great!
(Note: I put 4.04.0 instead of 4.03.0because when I explored the directory /usr/local/Cellar/ocaml/4.03.0/bin/ocaml but the directory /usr/local/Cellar/ocaml/4.04.0/bin/ocaml does)
How do I do check the instance of ocaml that is running?
If your question is: what program is running when you type ocaml in a terminal window at the shell prompt (or more generally thru execvp and other functions)? then you should use the which ocaml command.
And what does the poster mean by "prepending that url to your PATH environment"?
Read more about the PATH variable. It is often set in your ~/.bashrc file (which you should probably and carefully edit once using your favorite editor) -or some other bash initialization file- if your interactive shell is bash. You should check what it is with the echo $PATH command. See also this. Notice that ~/.bashrc is expanded by your shell during globbing. Read also the documentation of bash notably the Bash Startup Files chapter.
If you are using opam you should read its documentation. Notably this question (mentioning PATH) from its FAQ.
Since aliases are mostly for interactive shells, defining an alias is not enough for most shell scripts. You really need to change your $PATH and/or add files (or symlinks) in directories mentioned in it.
PS. Understanding the role of PATH and how to set it is mandatory for serious use of the command line, notably on POSIX systems.
In general, homebrew puts all its binaries, libraries and settings in /usr/local/Cellar/PACKAGENAME/VERSIONNUMBER but it also creates symbolic links in /usr/local/bin that point to the latest package/version.
So, if you look at my /usr/local/bin you will see:
ls -l /usr/local/bin
Output
lrwxr-xr-x 1 mark admin 26 30 Jan 2016 ack -> ../Cellar/ack/2.14/bin/ack
lrwxr-xr-x 1 mark admin 43 11 Oct 13:30 amqp-consume -> ../Cellar/rabbitmq-c/0.8.0/bin/amqp-consume
lrwxr-xr-x 1 mark admin 49 11 Oct 13:30 amqp-declare-queue -> ../Cellar/rabbitmq-c/0.8.0/bin/amqp-declare-queue
lrwxr-xr-x 1 mark admin 48 11 Oct 13:30 amqp-delete-queue -> ../Cellar/rabbitmq-c/0.8.0/bin/amqp-delete-queue
lrwxr-xr-x 1 mark admin 39 11 Oct 13:30 amqp-get -> ../Cellar/rabbitmq-c/0.8.0/bin/amqp-get
lrwxr-xr-x 1 mark admin 43 11 Oct 13:30 amqp-publish -> ../Cellar/rabbitmq-c/0.8.0/bin/amqp-publish
lrwxr-xr-x 1 mark admin 28 17 Jul 22:49 7z -> ../Cellar/p7zip/16.02/bin/7z
lrwxr-xr-x 1 mark admin 29 17 Jul 22:49 7za -> ../Cellar/p7zip/16.02/bin/7za
lrwxr-xr-x 1 mark admin 29 17 Jul 22:49 7zr -> ../Cellar/p7zip/16.02/bin/7zr
lrwxr
As you can see, ack points to version 2.14 of ack in the Cellar and so on.
In general therefore, when using homebrew, you should not directly use anything in the Cellar because that is version-specific. Instead, you should use /usr/local/bin and rely on that pointing to the latest/greatest thing in the Cellar. That way you won't have pain when upgrading and you won't have to change all your app-1.01 to app-1.0.2 in all your scripts because you will just be using app (which, by virtue of your PATH, means /usr/local/bin/app) instead of anything version-specific.
So, I would suggest you edit your bash profile, using TextEdit like this:
open -e ~/.profile
and add this line at the end:
export PATH=/usr/local/bin:$PATH
Remove all your version-specific aliases and log out and then back in again.

Executing MATLAB from Bash

I've been trying to work on opening/executing MATLAB from bash (I'm using Terminal, specifically). However, despite numerous attempts at troubleshooting, I have been unable to do it.
Running the "matlab" command gives me the error:
-bash: matlab: command not found
A cursory Google search suggested it could be an issue of my local bin, but my bin looks like:
/usr/local/bin:
total used in directory 16 available 208047788
drwxr-xr-x 4 alifarhat wheel 136 Jul 22 11:30 .
drwxr-xr-x 3 alifarhat wheel 102 Jan 22 01:56 ..
lrwxr-xr-x 1 alifarhat wheel 29 Jul 22 11:30 matlab -> /usr/local/matlab6/bin/matlab
lrwxr-xr-x 1 alifarhat wheel 26 Jul 22 11:30 mex -> /usr/local/matlab6/bin/mex
Which seems to indicate that matlab is talking to the bin.
If it helps, when I cd into /usr/local and then ls, the only directory/item in there at all is "bin". Could this have something to do with it? How can I fix it if it does?
It seems like PATH issues. Is /usr/local/bin in your $PATH?
Try
~$ echo $PATH
What do you see?
If /usr/local/bin is not part of your $PATH you can add it:
~$ export PATH=/usr/local/bin:$PATH
Then try and run matlab from shell
EDIT:
Based on these comments it seems like matlab executable is not located at /usr/local/matlab6/bin. Therefore, you can either
Add /Applications/MATLAB_R2014a.app/bin/ to path:
~$ export PATH=/Applications/MATLAB_R2014a.app/bin:$PATH
or
Replace the broken symbolic links in /usr/local/bin (you might need root privileges for this). See this thread for more details.
Once you are in the correct directory, you should execute the command:
./matlab
instead of just typing matlab.

Installed Ruby 1.9.3 manually, but ruby -v shows no such file or directory

On CentOS, I did a manual install of Ruby 1.9.3 from a tar file. I received no errors during the ./configure make and make install.
"which ruby" outputs "/usr/local/bin/ruby"
"whereis ruby" outputs "ruby: /usr/lib/ruby /usr/lib64/ruby /usr/local/bin/ruby /usr/local/lib/ruby"
"ruby -v" outputs "-bash: /usr/bin/ruby: No such file or directory"
echo $PATH outputs /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/dell/srvadmin‌​/bin:/opt/dell/srvadmin/sbin:/root/bin so it appears /usr/local/bin is before /usr/bin
You need to edit your PATH environment variable to look in /usr/local/bin before /usr/bin.
See this answer for details.
Simplest is to edit/create ~/.profile with the line:
export PATH=/usr/local/bin:$PATH
which adds that directory to be the first it looks in. (And then either create a new shell, or source ~/.profile to re-run the commands in it.)
Edit: If /usr/local/sbin (the first item in your PATH) has a symlink for ruby pointing to /usr/bin/ruby, you should either remove this file, or create a new symlink, e.g.
$ cd /usr/local/sbin
$ sudo rm ruby
$ sudo ln -s /usr/local/bin/ruby
$ ls -l ruby
lrwxr-xr-x 1 root root 19 Mar 18 09:01 ruby -> /usr/local/bin/ruby

$PATH is not working

The following file worked yesterday, but today it isn't working any more.
Could be caused by either the apt-get upgrade or autoremove that I performed.
For some reason $PATH isn't working, I have no idea why not.
$ cat GW
#!/bin/bash
PATH="/media/Data/Wine/WineVersions/1.3.24/bin:$PATH"
export WINEPREFIX="/media/Data/Wine/WinePrefixes/GW"
export WINEDEBUG="-all"
cd "/media/Data/Wine/WinePrefixes/GW/drive_c/Program Files/Guild Wars"
wine Gw.exe
$ ./GW
./GW: line 6: /media/Data/Wine/WineVersions/1.3.24/bin/wine: No such
file or directory
$ ls /media/Data/Wine/WineVersions/1.3.24/bin/wine
/media/Data/Wine/WineVersions/1.3.24/bin/wine
I also tried export PATH="blablabla" but that didn't work either.
Edit: Requested info
$ file /media/Data/Wine/WinePrefixes/GW/drive_c/Program\ Files/Guild\ Wars/Gw.exe
/media/Data/Wine/WinePrefixes/GW/drive_c/Program Files/Guild Wars/Gw.exe: PE32 executable for MS Windows (GUI) Intel 80386 32-bit
# Not a symlink
$ ls -l /media/Data/Wine/WineVersions/1.3.24/bin/wine gives -rwxr-xr-x 1 j j 7244
2011-08-11 17:18 /media/Data/Wine/WineVersions/1.3.24/bin/wine
Apparently /media/Data/Wine/WineVersions/1.3.24/bin/wine exists, but is an orphaned symlink or otherwise broken.
I autoremoved a bunch of libraries that wine required, I hadn't installed the standard wine package, instead using individual builds.
ia32-libs allowed the executable to start, I am cross-referencing the contents of /var/log/apt/history.log with apt-cache showpkg wine1.2 to find what I need to install.

Resources