Why does npm need sudo for EVERYTHING? - macos

I don't know how I've managed it but npm seems to need sudo for absolutely every command, even npm help does not work without sudo. If I use a command without sudo, I do not see am EACCESS error, but instead my terminal session hangs and then just closes that tab (I use iTerm on Mac).
I have tried changing the ownership of my local .npm folder, outlined here and also done the same on my /usr/local/bin folder where node is installed but none of these allow me to just run npm without sudo, even when installing local packages...! It seems to me that something has screwed along the way, can anyone help?
Many thanks

I encountered the same error after a fresh install of 0.12.4 today; this solved the problem for me:
sudo chown -R $(whoami):admin /usr/local/lib/node_modules
In my particular case, I noticed that this folder was owned by '{some-large-integer-account}:wheel'...YMMV
If that doesn't solve it, take a look at the ownership of the folders that are being blocked as mentioned in the EACCESS error trace. If you're not sure what the ownership should be, you can usually infer it from the sibling dirs' ownership.

I had this as well on my machine. What I did to fix it (there are probably much less extreme ways) was to completely remove npm, and then did a fresh installation node.js (with which npm is included) from http://nodejs.org/ making sure I didn't install as root. That then allowed me to use npm without root (except for global installs).

Take ember project for example, I give all related project directory root:
neil#neil-System-Product-Name:~/Projects/ember-quickstart$ sudo chown -R $(whoami) /home/neil/Projects/ember-quickstart/
neil#neil-System-Product-Name:~/Projects/ember-quickstart$ ember s
Could not start watchman
Visit https://ember-cli.com/user-guide/#watchman for more info.
Livereload server on http://localhost:7020
Build successful (10679ms) – Serving on http://localhost:4200/
Slowest Nodes (totalTime => 5% ) | Total (avg)
----------------------------------------------+---------------------
Babel (18) | 7561ms (420 ms)
Concat (8) | 1872ms (234 ms)
Rollup (1) | 629ms

Use the below option.
Open the terminal and cd to your Home directory and run the below command.
mkdir "${HOME}/.npm-packages"
Then this command after that.
npm config set prefix "${HOME}/.npm-packages"
Next, open your .zshrc file using the open -t .zshrc command and add the following to it.
NPM_PACKAGES="${HOME}/.npm-packages"
export PATH="$PATH:$NPM_PACKAGES/bin"
# Preserve MANPATH if you already defined it somewhere in your config.
# Otherwise, fall back to `manpath` so we can inherit from `/etc/manpath`.
export MANPATH="${MANPATH-$(manpath)}:$NPM_PACKAGES/share/man"

Related

Add to PATH from Laravel Sail Dockerfile

I'm trying to add sqlpackage to a Laravel Sail Docker. While this is normally not really difficult, Sail makes it kinda hard.
I have the following section in my Dockerfile
RUN curl -L https://go.microsoft.com/fwlink/?linkid=2157202 -o /usr/local/bin/sqlpackage.zip
RUN mkdir /usr/local/bin/sqlpackage
RUN unzip /usr/local/bin/sqlpackage.zip -d /usr/local/bin/sqlpackage
RUN rm /usr/local/bin/sqlpackage.zip
RUN echo "export PATH=\"\$PATH:$HOME/usr/local/bin/sqlpackage\"" >> /home/sail/.bashrc
RUN chmod a+x /usr/local/bin/sqlpackage/sqlpackage
First off, I'm not happy with the install path I've chosen (/usr/local/bin). But it's the best I could think of. Any suggestions are welcome.
My second, and more important issue is that I can't add run the echo to the path when installing. The install script can't reach the home path. Would really like a solution for this. But I get this error:
cannot create /home/sail/.bashrc: Directory nonexistent
However it exists. So it's a rights issue for the installing user. Any suggestions are welcome.
cannot create /home/sail/.bashrc: Directory nonexistent
It looks like user sail doesn't exist so
before
RUN echo "export PATH=\"\$PATH:$HOME/usr/local/bin/sqlpackage\"" >> /home/sail/.bashrc
Create user like below
# add user
RUN useradd sail
# and then
RUN echo "export PATH=\"\$PATH:/usr/local/bin/sqlpackage\"" >> /home/sail/.bashrc
Also $HOME is not required, because during build time it become
export PATH="$PATH:/root/usr/local/bin/sqlpackage"
Try below on terminal ( for example I am as root user ):
$ echo "export PATH=\"\$PATH:$HOME/usr/local/bin/sqlpackage\""
export PATH="$PATH:/root/usr/local/bin/sqlpackage"
Similar way during build process it will use current user that is root.
First off, I'm not happy with the install path I've chosen
(/usr/local/bin). But it's the best I could think of. Any suggestions
are welcome.
/usr/local/bin is the location for all add-on executables that you add to the system to be used as common system files by all users. Locally installed software must be placed within /usr/local.
# Used for non-system libraries and executables
/usr/local/bin
usr stands for User System Resources. This is the location that system programs and libraries are stored.
local represents resources that were not shipped with the standard distribution and, usually, compiled and maintained on a per site basis.
bin represents binary compiled executables.
So keep in mind these three
/usr/bin: User commands.
/usr/sbin: System administration commands.
/usr/local/bin: Locally customized software.
/opt is a directory for installing unbundled packages that is packages not part of the Operating System distribution, but provided by an independent source. I usually put all 3rd party packages in /opt

Is gvfs-trash installed? in Atom

When I tried to remove a file in local machine to check files are synchronous with vagrant development server it pops up an error:
The following file couldn't be moved to the trash.
Is gvfs-trash installed?
For solving it I created a trash directory that can be accessed from outside the user’s home directory:
# Create a Trash directory (with some subdirectories) in root
sudo mkdir -p /.Trash-1000/{expunged,files,info}
# Give ownership of this to your user:
sudo chown -R $USER /.Trash-1000
Still I can't remove the file from local machine. But If I delete a file at vagrant development server it automatically deletes at local machine, opposite is not happening and ends-up with this error "Is gvfs-trash installed? "
Like YuriAFGomes said, everything seemed to work fine in my system: trash folder had the right permissions and gvfs-trash worked flawlessly from command line, yet atom 1.45 said it couldn't delete any file. Tried to start atom with sudo and it didn't fix anything. Tried creating the .Trash-1000 directories in several places, and nothing, same error related to gvfs-trash. I'm pretty sure this used to work fine in my atom setup and suddenly it stopped doing so, and I have no idea why. I went to their releases list and tried downgrading to several of them until I settled with version 1.30, which doesn't seem to have this issue and is compatibles with my local packages. If you have this problem and tried everything said around the web, I suggest you try downgrading to different versions until the problem goes away.
There is an issue on GitHub reporting this problem. According to the report, a missing .Trash-1000 can cause this problem, so you can create it as follows.
mnt=/; id=$(id -u); sudo mkdir -p "$mnt/.Trash-$id"/{expunged,files,info} \
&& sudo chown -R $USER:$USER "$mnt/.Trash-$id"/ \
&& sudo chmod -R o-rwx "$mnt/.Trash-$id"/
Set mnt to the mount point, where gvfs-trash is expecting it.
Simply cd to the directory which will be opened in atom and execute df ..
This will give something like this:
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sdb1 960380628 463122460 448403708 51% /mnt/vol
In this example, the mount point and the value of mnt would be /mnt/vol.
What solved this issue for me was uninstalling atom via dpkg and installing it via apt from the following PPA: https://launchpad.net/~webupd8team/+archive/ubuntu/atom . I have no clue why this works, though. I have noticed that the PPA installs atom 1.26, while the version where the issue arised, installed via dpkg, is 1.45.
Before doing that, I have tried creating the .Trash-1000 directories in root, in home and in project folder, with the proper permissions. gvfs-trash was installed, updated and working as expected all the time, but the problem persisted. Really odd.
The real problem is that atom/electron are/were using gvfs-trash which has been deprecated for almost 5 years. Electron which is the platform on which Atom is built has fixed this in the development branch but hasn't backported it to the 2.0 branch on which Atom is based.
Solution/Workaround as of now?
Use an environment variable $ELECTRON_TRASH and set it to gio or one of the alternatives
See if you are missing the .Trash-1000 folder (assuming your uid is 1000)
Install an alternate gvfs-trash script to take over the missing functionality
Delete the file/folder outside of atom
I had a similar problem on Windows using Atom, where I couldnt delete the files. So I resorted to deleting them manually from the directory (outside of Atom).
Turns out atom cannot "move to trash" if u checked in recycle bin this option:
"Don't move files to the Recycle Bin. Remove files immediately when deleted."
Just set the other option (to move files to actual recycle bin) and should work.

NPM Install Error | Text File is Busy, Unlink

Getting this error when running sudo npm install --force --no-bin-links within project folder. Below is the error I'm receiving. It looks like it keeps renaming some of the nodes. I go into the actual folder and remove the #s at the end, but when I run the install again, it just re-adds them...not sure what's going on.
Thank you!
"ETXTBSY is a file sharing violation at the system level, and it indicates that another process has the file already opened and holds the lock for it." (source)
It means that npm is trying to overwrite a locked file. You have to stop the process holding the lock to be able to overwrite that file.
The process PID can be found with
fuser -u <package.json.somenumber

Final permissions on OS X Bower and NPM

hope you having a good day.
I am a Web Frontend designer and i'm tired about MAC OSX El Capitan and his sick permissions systems on files and folders, the next is happening:
Every time that i tried to get any Bower package, NPM, or whatever console package i get this problem:
Example: 'Bower install angular-translate'
Console response:
'Error: EACCES: permission denied, open '/Users/carl/.config/configstore/bower-github.json'
You don't have access to this file.'
This is not just for this package in specific, it happend with everything that i tried to download/install in every place in my laptop.
I am the administrator on this machine, i been google that like 5 or 10 times always getting same results and always going to the same way (solutions like 'chmod-R 777* on the folder/file').
My question is the next:
There is some 'permanent' way to get all my files and folders 'global' administrator permissions no matter what? i mean, i know that is not secure, pero it is ok, i am the only one who use this laptop.
Thank you so much for your help.
Best Regards.
In order to solve the issue. I ran the command 'sudo chown -R $USER ~/' from the terminal. While inside the same terminal window, I then ran 'bower install' which solved my issue! Afterwards, I was able to install other packages(Ex. bower install bootstrap --save.

Meteor requires sudo to run

Previously I was able to start Meteor 0.6.6.3 by simply running mrt.
Recently, Meteor 0.7.0.1 wont run properly unless I run it as root with sudo mrt. Environmental variables like MONGO_URL requires root to set it.
Any ideas what happened? I'm using Mountain Lion on Mac OSX.
You might have run it with sudo once before. When you run it with sudo just once and a file is written the files become root files root user file so it needs more permissions to run and wont run
ordinarily.
You might have run sudo mrt once it must have updated files for a package but they're now owned by root instead of your normal user.
I'm sure theres a terminal command to get it back but using Disk Utility and running 'Repair Disk Permissions' can also fix it (i think).

Resources