In my Makefile I'm trying to copy the executable file into usr/local/bin.
install:
sudo cp program1 usr/local/bin
My Makefile and program1-file is in a directory src in Documents so this doesn't work. I probably need the whole path from my src directory.
Is there a general way to make it work regardless of where I put my directory with the Makefile and executable? Maybe using the PATH variable or something?
usr/local/bin is a relative path. If you don't want that, use an absolute path:
install:
cp whatever /usr/local/bin
Some tips:
Don't use sudo in your Makefile, that's unusual. Note in the installation docs that the install target has to be run by a user with sufficient privileges (and people will do sudo make install when they want to)
Look into the install (man install), it's meant for this sort of thing.
Related
Fresh install of macOS Sierra on a new MBP, /usr/local/bin requires root to access the files. But many programs, including node and npm install their executables to /usr/local/bin. I can't execute them unless I'm root. Am I supposed to change permissions on /usr/local/bin in macOS Sierra? Seems there's a reason for the stricter permissions.. Are tools like node/npm just not up to date with how things are done in the latest mac OS and I should move those files to somewhere else like /usr/bin?
Change npm's default directory to another directory that requires you not to run it as root
mkdir ~/my/path
npm config set prefix '~/my/path'
Open or create a ~/.profile file and add this line:
export PATH=~/my/path/bin:$PATH
Back on the command line, update your system variables:
source ~/.profile
Test: Download a package globally without using sudo.
How is it to execute something like sudo npm rebuild or sudo node if Node.js was installed by NVM ?
Each time I type sudo command, my console tries to execute npm or node program in /usr/bin/ or /usr/lib, neither of which do exist.
Try creating symlinks in /usr/bin or /usr/lib. Not a strong solution, but may be enough.
sudo ln -s /home/denny/.nvm/versions/node/v0.12.0/bin/npm /usr/bin/npm
sudo for writing in system location. Suggestions here may happen useful, especially rvmsudo or group access.
Other suggestion:
According to comment, you may try to create a bash script at /home/denny/npm.sh:
#!/bin/bash
PTH="/home/denny/.nvm/versions/node/$(node -v)/bin/npm"
$PTH
chmode it +x properly and create symlink with this:
sudo ln -s /home/denny/npm.sh /usr/bin/npm
Should always check for node -v and run npm from proper directory.
I needed to do this to run the Atom installation script, but I didn't want to permanently change my machine setup. So, I did:
sudo bash
and then I sourced the nvm.sh file in my user's home directory tree:
source /home/ada-lovelace/.nvm/nvm.sh
That let me run the necessary commands with root. Of course, this means the very next time I need to run node in a session with root I'll have to do these steps again, but I don't anticipate needing to do this in the near future.
I suipidly ran this script to stop having to use sudo on npm -g commands and now my node_modules are located at:
/Users/myusername/.npm-packages/lib/node_modules
when trying to run a commands i.e yo bower i get -bash: bower: command not found
Do I need to link this directory to the usr/bin?
In trying to sort this out I have run lots of commands and created symbolic links, I feel like my system is a real mess and I cannot really see what is going on? Help to ensure my system is clean would be really helpful.
Generally, it's a good idea to ensure that you do not need admin rights to run npm commands. The problem you're having, is that the directory where npm now installs its commmands (/Users/myusername/.npm-packges/bin) is not in your PATH. Your PATH is a list of directories where your shell searches for the commands you type.
You can add the directory to your path by adding the following line to the .bashrc file in your home directory (create it if it doesn't exist).
export PATH="${PATH}:/Users/myusername/.npm-packages/bin"
Open a new terminal, and bower should work again.
As an additional tip, I believe you're running on OS X? When installing Node.js using Homebrew, it is automatically installed in a proper way (no sudo needed to install packages globally and they will just work). Next time you're installing Node.js (or something else), Homebrew might be worth a try.
I'm on cygwin to do unix commands on win7 (launched cygwin.bat in windows cmd prompt).
My project directories are created in root like this:
$ mkdir -p app/models
$ mkdir -p app/node_modules
Then the symlink is created:
$ cd app/node_modules
$ ln -sf ../models
Back on the /app/ directory, I go into Node console to launch the module located in
app/models/movie.js:
Movie = require('models/movie');
But I get the following error:
Cannot find module 'models/movie'
ln takes 2 arguments, not one.
I found out that cygwin doesn't really create actual symlinks by default. I had to create native NTFS symlinks using export CYGWIN="winsymlinks:native"
For example I tried installing npm serve globally
$ npm install -g serve
but after seemingly successfully installing it, I was unable to run the serve executable. Seems like the command just could not be found. Turns out the exe serve file was located in:
usr/local/share/npm/bin
rather than in what I thought should be (where all the other executable files are):
usr/local/bin
Any idea why I can't seem to get this to work?
Similar to this answer, create/edit ~/.npmrc to include:
prefix = /usr/local/bin