I have been using rbenv for ruby for a while, and I have not had a problem with files being tracked; everything seems to be in it's place, and I haven't really had an issue.
I recently switched to rvm for a new project, and had to change a couple things to my environment. As a result, whenever I now run bundle, all of the gems that were added to my project become tracked via git looking something like this;
new file: vendor/bundle/ruby/2.2.0/bin/aws-rb
new file: vendor/bundle/ruby/2.2.0/bin/byebug
new file: vendor/bundle/ruby/2.2.0/bin/erubis
new file: vendor/bundle/ruby/2.2.0/bin/geocode
new file: vendor/bundle/ruby/2.2.0/bin/nokogiri
new file: vendor/bundle/ruby/2.2.0/bin/rackup
new file: vendor/bundle/ruby/2.2.0/bin/rails
new file: vendor/bundle/ruby/2.2.0/bin/rake
new file: vendor/bundle/ruby/2.2.0/bin/rdoc
new file: vendor/bundle/ruby/2.2.0/bin/ri
new file: vendor/bundle/ruby/2.2.0/bin/sass
new file: vendor/bundle/ruby/2.2.0/bin/sass-convert
new file: vendor/bundle/ruby/2.2.0/bin/scss
new file: vendor/bundle/ruby/2.2.0/bin/sdoc
new file: vendor/bundle/ruby/2.2.0/bin/sdoc-merge
new file: vendor/bundle/ruby/2.2.0/bin/spring
new file: vendor/bundle/ruby/2.2.0/bin/sprockets
new file: vendor/bundle/ruby/2.2.0/bin/thor
new file: vendor/bundle/ruby/2.2.0/bin/tilt
new file: vendor/bundle/ruby/2.2.0/bin/unicorn
new file: vendor/bundle/ruby/2.2.0/bin/unicorn_rails
new file: vendor/bundle/ruby/2.2.0/cache/actionmailer-4.2.6.gem
new file: vendor/bundle/ruby/2.2.0/cache/actionpack-4.2.6.gem
new file: vendor/bundle/ruby/2.2.0/cache/actionview-4.2.6.gem
new file: vendor/bundle/ruby/2.2.0/cache/activejob-4.2.6.gem
new file: vendor/bundle/ruby/2.2.0/cache/activemodel-4.2.6.gem
new file: vendor/bundle/ruby/2.2.0/cache/activerecord-4.2.6.gem
new file: vendor/bundle/ruby/2.2.0/cache/activesupport-4.2.6.gem
and because of this, github doesn't display the entirety of my commits, my git add's take forever, overall it's just very messy.
With rbenv I did not have this problem, so I can only assume it's something to do with how I set up rvm. Here's my current bash_profile
# Set architecture flags
export ARCHFLAGS="-arch x86_64"
# Ensure user-installed binaries take precedence
export PATH=/usr/local/bin:/usr/local/sbin:$PATH
# RBENV - add bin and shims to path
export PATH=$HOME/.rbenv/bin:$PATH
eval "$(rbenv init -)"
# Bash completion
if [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion
fi
# Git completion
if [ -f ~/.git-completion.bash ]; then
source ~/.git-completion.bash
fi
# Aliases
alias b="bundle exec"
alias t="RAILS_ENV=test"
alias bi="bundle install; rbenv rehash"
alias bu="bundle update; rbenv rehash"
# message from RVM (5/2/16)
# first attempt below
#source /Users/username/.rvm/scripts/rvm
# next attempt below
source ~/.rvm/scripts/rvm
I believe this current tracking is due to how my path's are set up, and that is something I do not know too much about currently.
I was wondering if anyone has had some experience with this, if they could tell me how I could stop all of the gems I download from being tracked by git. Any help would be appreciated :)
here's my .bundle/config file
---
BUNDLE_PATH: vendor/bundle
BUNDLE_DISABLE_SHARED_GEMS: true
here's the output of rvm env
export PATH="/Users/username/.rvm/gems/ruby-2.2.3/bin:/Users/username/.rvm/gems/ruby-2.2.3#global/bin:/Users/username/.rvm/rubies/ruby-2.2.3/bin:$PATH"
export GEM_HOME='/Users/username/.rvm/gems/ruby-2.2.3'
export GEM_PATH='/Users/username/.rvm/gems/ruby-2.2.3:/Users/username/.rvm/gems/ruby-2.2.3#global'
export MY_RUBY_HOME='/Users/username/.rvm/rubies/ruby-2.2.3'
export IRBRC='/Users/username/.rvm/rubies/ruby-2.2.3/.irbrc'
unset MAGLEV_HOME
unset RBXOPT
export RUBY_VERSION='ruby-2.2.3'
here's the output of which ruby
/Users/username/.rvm/rubies/ruby-2.2.3/bin/ruby
You have to remove .bundle/config (It's a per project configuration that overrides your user preferences).
Ensure you are using right Ruby's version ($rvm list rubies will show your current Ruby version used in this current path)
If you're using the required Ruby version for the project then you should have installed bundler gem for this Ruby version and it should be work.
You should add a .gitignore file.
Related
I have my bundler configured to install gems into a .bundle/ directory inside each project.
$ cat ~/.bundle/config
---
BUNDLE_PATH: ".bundle"
BUNDLE_BIN: ".bundle/bin"
How can I make RVM respect this setting and not set the $GEM_HOME to another directory (inside ~/.rvm/) whenever I cd into my project?
So far I had a little script that would set $GEM_HOME (and $PATH and $GEM_PATH) whenever I would cd inside my project's directory, but with recent versions of rvm it has stopped working and now RVM basically unsets the Ruby version whenever I manually change $GEM_HOME and I have no clue how to make it work again.
First of all you should specify that you want to use the very separate gemset for your project (consider it’s name is myproject42):
$ cd myproject42 && rvm --rvmrc --create use 2.1.0#myproject42 --ignore-gemsets
rvmrc option will create the configuration file in your folder. You are already half-separated from the universe. Now you want to modify this file a bit, setting whatever you want:
...
unset __hook
# my exports
export GEM_PATH=`pwd`
export GEM_HOME=`pwd`
...
cd out and back in into this directory. This will result in the warning:
You are using '.rvmrc', it requires trusting, it is slower and ...
[LINES SKIPPED]
************************
y[es], n[o], v[iew], c[ancel]> y
Using: /tmp/myproject42
Once you confirm you are aware of this modification, the gemset is set to what you wanted (/tmp/myproject42 in this case.) You may verify that:
$ rvm gemset dir
Warning! PATH is not properly set up, '/tmp/myproject42/bin' is not available,
[LINES SKIPPED]
/tmp/myproject42
You might want to make some cleanup, like suppressing those warnings. The “howtos” are printed out inside this warnings, they are pretty straightfoward so I left the description of initial process “dirty” to show it exactly how it would be run on your machine.
I hope this helps.
RVM supports .ruby-version and .ruby-gemset on a per project basis and ensures those are set correctly when you navigate to a directory containing those files.
Is there a similar construct I can use for adding directories to my environment PATH variable using RVM?
I haven't found a way to do this using RVM, but I came across another project called direnv that accomplishes exactly what I want.
Here are the steps I took to prepend ./bin to my environment PATH variable on OSX every time I go to my project directory in the shell:
brew install direnv
Add eval "$(direnv hook $0)" to the end of my .zshrc file.
Create a .envrc file in the root of my project with the following content:
PATH_add bin
I'm trying to set my $GOPATH variable to run some example code on my machine:
$ smitego-example go run main.go
main.go:5:2: cannot find package "github.com/#GITHUB_USERNAME#/smitego" in any of:
/usr/local/go/src/pkg/github.com/#GITHUB_USERNAME#/smitego (from $GOROOT)
($GOPATH not set)
$ smitego-example export $GOPATH=$HOME
-bash: export: `=/Users/#OSX_USERNAME#': not a valid identifier
Contents of github.com/#GITHUB_USERNAME#/smitego/smitego.go:
package smitego
How can I set my GOPATH so it works always and forever?
Update, as of Go 1.8: If you're installing Go 1.8 (released: Feb 2017) or later, GOPATH is automatically determined by the Go toolchain for you.
It defaults to $HOME/go on macOS (nee OS X) - e.g. /Users/matt/go/. This makes getting started with Go even easier, and you can go get <package> right after installing Go.
For the shell: (the manual method)
~/.bash_profile should contain export GOPATH=$HOME/go and also export PATH=$GOPATH/bin:$PATH. The use of the $ is important: make sure to note where I've used it (and where I have not).
For Sublime Text:
Sublime Text menu > Preferences > Package Settings > GoSublime > Settings: User
{
"shell": ["/bin/bash"],
"env": {"GOPATH": "/Users/#USERNAME#/go/"},
}
Make sure your GOPATH is not set to the full path of the package; just the root of your go folder where src, pkg, and bin reside. If you're not using GoSublime, I'd suggest installing that first.
The accepted answer didn't work for me. I investigated and found the cause: I am using zsh, not bash.
I need to add the following two lines to ~/.zshrc:
export GOPATH=/Users/username/go
export PATH=$GOPATH/bin:$PATH
You don't put the $ prefix on a variable when you're assigning it, only when you're reading it.
export GOPATH=$HOME
To make this permanent, put the command in your .bash_profile.
That will work for Terminal shells. If you need to set environment variables that will affect GUI applications, see Environment variables in Mac OS X
Download and install Go tools
https://golang.org/doc/install
Setup Go workspace
mkdir $HOME/go && cd $HOME/go
mkdir bin pkg src
Setup Go environment
sudo vi ~/.bash_profile
export GOPATH=$HOME/go
PATH=$PATH:$GOPATH/bin
Test by creating, building and running a Go project
mkdir -p $GOPATH/src/github.com/todsul/hello
touch $GOPATH/src/github.com/todsul/hello/hello.go
go install
hello
The http://www.golang-book.com/guides/machine_setup#osx
only has instructions for setting the path on ~/.bashrc, not ~/.bash_profile which thanks to this thread was able to get my example file to build.
export GOPATH=$HOME
export PATH=$PATH:$GOPATH/bin
Other Mac users need to add the above to their ~/.bash_profile.
After installing go with brew or with package this solved my problem:
export GOROOT="/usr/local/go"
export GOPATH="$HOME/Documents/goWorkSpace"
export PATH="$HOME/Documents/goWorkSpace/bin:$PATH"
on macOS High Sierra Version 10.3.3, Go[go version go1.10.1 darwin/amd64] Installed here :
Added following on :~/.bashrc
export GOPATH=/usr/local/go
export PATH=$PATH:$GOPATH/bin
and then Go Works
People working with the latest macs and above Catalina version,
you guys need to update the .zshrc file instead of .bash.
Add the following two lines to ~/.zshrc:
export GOPATH=/Users/username/go
export PATH=$GOPATH/bin:$PATH
it should work.!!
This got change a while back, please refer to the link below to understand why .zshrc and not .bash_profile
https://eshop.macsales.com/blog/56921-moving-from-bash-to-zsh-terminal-changes-in-macos-catalina/
I keep getting Command Not Found: prettify_json.rb from the command line. I'm using zsh and rvm so, I'm not sure if it has something to do with the paths setting in my .zshrc. I've compared it to some other questions here with similar problems and I'm not able to see an issue.
here is the .zshrc file:
ZSH=$HOME/.oh-my-zsh
alias vi="vim"
source $ZSH/oh-my-zsh.sh
source ~/.git-flow-completion.zsh
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
export PATH=/usr/local/bin:$PATH
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
The json gem may not have shipped with prettify_json.rb. But it is available in the json-utils gem. Try gem install json-utils
Is it possible to have rvm know which gemset it should be using while navigating under a certain directory, much in the same way you can have git the current branch's information just by navigating under that directory?
I understand how git works that way since each directory has its own .git directory in the root, but didn't know if it was possible since .rvm is more of a user-wide configuration. Or perhaps the answer is to make a .rvm file within each directory?
For others visiting this, there is a new way to do this, without having to allow arbitrary shell script to be executed in a .rvmrc file.
Create a file named .ruby-gemset containing only the gemset name in.
gemset
Need an up to date version of rvm for this to work.
You can also specify the ruby version by creating a file named .ruby-version containing only the ruby version:
1.9.3
This format also has the advantage of being compatible with rbenv and rbfu.
If you have existing projects using the deprecated .rvmrc, you can convert them to the new format using the command:
rvm rvmrc to .ruby-version
Create a .rvmrc file in each project/branch with contents similar to this:
rvm gemset use xxxx
Save it. Next time you cd into that folder, you'll probably get a security prompt from RVM to make sure you want to use that .rvmrc. After accepting, you'll see "Now using gemset 'xxxx'" every time you navigate into that folder.
I find the easiest way to achieve this is to navigate to the project folder and then use the following command:
rvm --rvmrc --create <ruby>#<desired-gemset-name>
e.g. rvm --rvmrc --create 1.9.2-p290#testing_gemset
In one stroke, RVM will create the .rvmrc file, populate it, install the correct ruby version - if necessary - and (usually) switch to the correct ruby version and gemset. I say usually because I find that I sometimes have to cd . after performing that command to get RVM to pick up the changes.
Create a .ruby-version file with the contents [ruby version]#[gemset] in the project folder.
Example:
$ rvm gemset list
gemsets for ruby-2.6.3 (found in /home/ec2-user/.rvm/gems/ruby-2.6.3)
(default)
hello
=> sample
toy
$ echo "2.6.3#sample" > .ruby-version
If you cannot get .ruby-version / .ruby-gemset working, consider whether your terminal is using shell login and try running the command in the shell section at http://rvm.io/support/faq:
$ rvm get [head|stable] --auto
It is possible: http://rvm.io/workflow/rvmrc/:
rvm use ruby#gemset