Permission Denied Message on Terminal Startup – MacOS, Bash, Terminal

bashmacosterminal

Everytime I start my Terminal I get this error message:

-bash: /Users/myusername/.profile: Permission denied

I still can use the Terminal as usual though.

It probably came after I installed something that is using the terminal.
It seems that something is trying to access .profile which doesn't exist.
Note that .bash_profile exist.

I ran the command:

grep -n profile ~/.* 2>/dev/null

And got this result:

/Users/myusername/.v8flags.3.14.5.9.myusername.json:1:["--use_strict","--es5_readonly","--es52_globals","--harmony_typeof","--harmony_scoping","--harmony_modules","--harmony_proxies","--harmony_collections","--harmony","--packed_arrays","--smi_only_arrays","--clever_optimizations","--unbox_double_arrays","--string_slices","--crankshaft","--hydrogen_filter","--use_range","--eliminate_dead_phis","--use_gvn","--use_canonicalizing","--use_inlining","--max_inlined_source_size","--max_inlined_nodes","--max_inlined_nodes_cumulative","--loop_invariant_code_motion","--collect_megamorphic_maps_from_stub_cache","--hydrogen_stats","--trace_hydrogen","--trace_phase","--trace_inlining","--trace_alloc","--trace_all_uses","--trace_range","--trace_gvn","--trace_representation","--stress_pointer_maps","--stress_environments","--deopt_every_n_times","--trap_on_deopt","--deoptimize_uncommon_cases","--polymorphic_inlining","--use_osr","--array_bounds_checks_elimination","--array_index_dehoisting","--dead_code_elimination","--trace_dead_code_elimination","--trace_osr","--stress_runs","--optimize_closures","--lookup_sample_by_shared","--cache_optimized_code","--inline_construct","--inline_arguments","--inline_accessors","--loop_weight","--optimize_for_in","--opt_safe_uint32_operations","--parallel_recompilation","--trace_parallel_recompilation","--parallel_recompilation_queue_length","--experimental_profiler","--watch_ic_patching","--frame_count","--self_optimization","--direct_self_opt","--retry_self_opt","--count_based_interrupts","--interrupt_at_exit","--weighted_back_edges","--interrupt_budget","--type_info_threshold","--self_opt_count","--trace_opt_verbose","--debug_code","--code_comments","--enable_sse2","--enable_sse3","--enable_sse4_1","--enable_cmov","--enable_rdtsc","--enable_sahf","--enable_vfp3","--enable_vfp2","--enable_armv7","--enable_sudiv","--enable_movw_movt","--enable_unaligned_accesses","--enable_fpu","--expose_natives_as","--expose_debug_as","--expose_gc","--expose_externalize_string","--stack_trace_limit","--builtins_in_stack_traces","--disable_native_files","--inline_new","--stack_trace_on_abort","--trace","--mask_constants_with_cookie","--lazy","--trace_opt","--trace_opt_stats","--opt","--always_opt","--prepare_always_opt","--trace_deopt","--min_preparse_length","--always_full_compiler","--max_opt_count","--compilation_cache","--cache_prototype_transitions","--trace_debug_json","--debugger_auto_break","--enable_liveedit","--break_on_abort","--stack_size","--max_stack_trace_source_length","--always_inline_smi_code","--max_new_space_size","--max_old_space_size","--max_executable_size","--gc_global","--gc_interval","--trace_gc","--trace_gc_nvp","--trace_gc_ignore_scavenger","--print_cumulative_gc_stat","--trace_gc_verbose","--trace_fragmentation","--trace_external_memory","--collect_maps","--flush_code","--incremental_marking","--incremental_marking_steps","--trace_incremental_marking","--track_gc_object_stats","--use_idle_notification","--use_ic","--native_code_counters","--always_compact","--lazy_sweeping","--never_compact","--compact_code_space","--incremental_code_compaction","--cleanup_code_caches_at_gc","--random_seed","--use_verbose_printer","--allow_natives_syntax","--trace_parse","--trace_sim","--check_icache","--stop_sim_at","--sim_stack_alignment","--abort_on_uncaught_exception","--trace_exception","--preallocate_message_memory","--randomize_hashes","--hash_seed","--preemption","--regexp_optimization","--testing_bool_flag","--testing_int_flag","--testing_float_flag","--testing_string_flag","--testing_prng_seed","--testing_serialization_file","--extra_code","--dump_counters","--debugger","--remote_debugger","--debugger_agent","--debugger_port","--map_counters","--js_arguments","--debug_compile_events","--debug_script_collected_events","--gdbjit","--gdbjit_full","--gdbjit_dump","--gdbjit_dump_filter","--force_marking_deque_overflows","--stress_compaction","--log","--log_all","--log_runtime","--log_api","--log_code","--log_gc","--log_handles","--log_snapshot_positions","--log_suspect","--prof","--prof_auto","--prof_lazy","--prof_browser_mode","--log_regexp","--sliding_state_window","--logfile","--ll_prof","--gc_fake_mmap"]

I also added set -x at the end of the /etc/profile file and got this result:

Last login: Mon Oct  5 21:54:04 on ttys001
+ export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/bin
+ PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/bin
+ export PATH=/Applications/MAMP/bin/php/php5.5.10/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/bin
+ PATH=/Applications/MAMP/bin/php/php5.5.10/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/bin
+ /Users/myusername/.profile
-bash: /Users/myusername/.profile: Permission denied
+ [[ -s /Users/myusername/.rvm/scripts/rvm ]]
+ source /Users/myusername/.rvm/scripts/rvm
++ builtin test -n '3.2.53(1)-release' -o -n '' -o -n ''
++ case "`uname`" in
+++ uname
+++ command ps -p 14417 -o ucomm=
+++ ps -p 14417 -o ucomm=

To me, it looks like the application MAMP is causing the problem, am I right?

Best Answer

To investigate your issue with startup rc files, you can generate trace for each command, e.g.:

  1. Edit /etc/profile (e.g. sudo vim /etc/profile).
  2. Append set -x at the end of the file.
  3. Open new Terminal window and it'll show the trace output.

Having trace output, you can easily identify the source of your Permission denied issue (by search for it via: +f). Once you remove the problematic line, get rid of set -x which you've appended.

Related Question